src2020/4094_can/can.cpp

43 lines
982 B
C++
Raw Normal View History

2020-04-18 08:22:40 +08:00
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int dao[100001]={0},yao[100001]={0},n,mins=1,ans=0;
bool pan[100001]={0};
cin>>n;
for(int i=0;i<n;i++){
cin>>dao[i]>>yao[i];
if(dao[i]<dao[mins]){
mins=i;
}
}
int now=dao[mins]+yao[mins];
pan[mins]=1;
for(int i=1;i<n;i++){
bool xu=0;
int xiao=1000000001,zhi=0;
for(int j=0;j<n;j++){
if(dao[j]<now&&pan==0){
int zhe=now-dao[j];
if(zhe>ans){
ans=zhe;
}
pan[j]=1;
now+=zhe;
xu=1;
break;
}
if(dao[j]<xiao&&pan[j]==0){
xiao=dao[j];
zhi=j;
}
}
if(xu==0){
now=dao[zhi]+yao[zhi];
pan[zhi]=1;
}
}
cout<<ans;
}