思路
对于每个草莓返回时间有两种情况
1.无需等待成熟,时间为 。
2.需要等待成熟,时间为 。
所以我们处理每个草莓所需时间,其中的最大值一定覆盖了其他草莓所需时间,最后在处理最大往返所需时间,最大值就是答案。
代码
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int N=1e6+6;
int n,mx,ans;
struct node{
int a,t;
}c[N];
bool cmp(node b,node d){
return b.a>d.a;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>c[i].a>>c[i].t;
sort(c+1,c+n+1,cmp);
for(int i=1;i<=n;i++){
ans=max(ans,c[i].t+c[i].a);
ans=max(ans,2*c[i].a);
}
mx=c[1].a;
ans=max(ans,2*mx);
cout<<ans;
return 0;
}