先举个栗子:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 //时间倒流 5 using namespace std; 6 7 const int maxn = 1e6 + 5; 8 9 int n; 10 struct node{ 11 int a, b; 12 } e[maxn]; 13 14 inline bool cmp(node x, node y){ 15 return x.b > y.b; 16 } 17 18 int main(){ 19 scanf("%d", &n); 20 for(int i = 1; i <= n; i++) 21 scanf("%d%d", &e[i].a, &e[i].b); 22 sort(e + 1, e + 1 + n, cmp); 23 int t = e[1].b; 24 for(int i = 1; i <= n; i++){ 25 if(t > e[i].b) t = e[i].b; 26 t -= e[i].a; 27 } 28 printf("%d\n", t); 29 return 0; 30 }
原文:https://www.cnblogs.com/New-ljx/p/11246843.html