Sort the task time in ascending order to save the time that the current soldier can spend with others. Find the maximum value for a business trip, and explain the time required for each soldier's task as the answer.
# Include <cstdio> # include <algorithm> # include <iostream> # include <cstring> using namespace std; struct node {int x, y;} man [1005]; int last [1005]; bool cmp (const node & a, const node & B) {return. y> B. y;} int main () {int n; int cas = 1; while (scanf ("% d", & n) {int ans = 0; int sum = 0; last [n] = 0; for (int I = 1; I <= n; I ++) {scanf ("% d ", & man [I]. x, & man [I]. y); sum + = man [I]. x;} sort (man + 1, man + 1 + n, cmp); for (int I = n-1; I> = 1; I --) {last [I] = last [I + 1] + man [I + 1]. x ;}for (int I = 1; I <= n; I ++) {if (man [I]. y> last [I]) ans = max (ans, man [I]. y-last [I]);} printf ("Case % d: % d \ n", cas ++, ans + sum);} return 0 ;}