记录编号 |
380927 |
评测结果 |
AAAAAAAA |
题目名称 |
挤牛奶 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2017-03-10 16:45:57 |
内存使用 |
0.39 MiB |
显示代码纯文本
//\
465.挤牛奶\
g++ 465.挤牛奶.cpp -O2 -D LOCAL -D debug
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define is_num(tmp) (tmp<='9' and tmp>='0')
inline int in(void){
char tmp(getchar());
int res(0),f(1);
while(!(is_num(tmp)||tmp=='-'))tmp=getchar();
if(tmp=='-')f=-1,tmp=getchar();
while(is_num(tmp))
res=(res<<1)+(res<<3)+(tmp^48),
tmp=getchar();
return res*f;
}
#define MAXN 10000
struct NODE{
int sta, end;
void Get(void){
sta = in(), end = in();
}
void Put(void){
printf("%d %d\n", sta, end);
}
bool operator<(const NODE&a)const{
if(sta != a.sta)return sta < a.sta;
return end < a.end;
}
}s[MAXN];
int N, max_1, max_2;
int main(){
#ifndef LOCAL
freopen("milk2.in","r",stdin);
freopen("milk2.out","w",stdout);
#endif
N=in();
for(int i = 1; i <= N; ++i){
s[i].Get();
}
sort(s+1, s+1+N);
#ifdef debug
for(int i = 1; i <= N; ++i){
s[i].Put();
}
#endif
int i = 1, cnt = 1, tmp = 0;
int L = s[1].sta, R = s[1].end;
max_1 = R - L;
while(i <= N){
++i;
if(s[i].sta <= R){
if(s[i].end > R)R = s[i].end;
}
else{
max_2 = max(max_2, s[i].sta - R);
max_1 = max(max_1, R - L);
L = s[i].sta,
R = s[i].end;
}
}
printf("%d %d", max_1, max_2);
return 0;
}