思路:
二分最晚工作点,贪心:先做截至时间做靠前的
结合以上二位大侠,我们给出ACcode!:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+10;
int n;
struct E{
int t,s;
bool operator<(const E& i)const{
return s<i.s;
}
}e[N];
bool check(int x){
int ti=x;
for(int i=1;i<=n;i++){
if(ti+e[i].t<=e[i].s){
ti+=e[i].t;
}
else return false;
}
return true;
}
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>e[i].t>>e[i].s;
sort(e+1,e+1+n);
int l=-1,r=1000000+1;
while(l+1<r){
int mid=l+r>>1;
if(check(mid))l=mid;
else r=mid;
}
cout<<l<<"\n";
}
int main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int tt=1;
// cin>>tt;
while(tt--)
solve();
return 0;
}
over~