nefu989考试安排

description

开学一个月之后,又到了考试月,不过现在老师比较开明,除了老师自己安排的时间表ai外,小明也给他自己安排了一个时间表;小明可以在任意一科的考试可以从他自己安排的时间选,也可以就按照老师的安排来,但是要保证考试安排日程是非递减序列,求满足这个条件的最后一天考试时间。不能改变老师安排的考试的先后次序

input

给定一个n代表考试的科目总数,剩下n行 ,每行两个数ai,bi,ai代表老师安排的时间,bi代表自己安排的时间。1<=n<=5000,0<=5000;

output

输出花的最少的时间。

sample_input

35 23 14 236 15 24 3

sample_output

26

hint

最先考的是第2个课程,然后在第2天考剩下的两科。第二个样例 先考第三个,然后第二个,然后第一个。

水啊~~

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct time
{
     int a,b;
     bool operator <(const struct time &other )const
{
     if (a!=other.a) return a<other.a;
     return b<other.b;
}
}m[5500];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
         for(int i=0;i<n;i++) scanf("%d%d",&m[i].a,&m[i].b);
         sort(m,m+n);
         int s=min(m[0].b,m[0].a);
         for(int i=1;i<n;i++)
         {
              if(s<=m[i].b)
              s=m[i].b;
              else s=m[i].a;
         }
         printf("%d\n",s);
    }
    return 0;
}


全部评论

相关推荐

祈求顺利毕业😁:简历很好了,多投吧牛油😂。主要是环境不好,大家也卷
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务