Commando War UVA - 11729
題意:
有n個任務,每個任務有交待時間 B i B_i Bi,執行時間 J i J_i Ji。每個任務的執行互相獨立。
思路:
對執行時間從大到小排序。
AC
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
const int maxn = 1e3+10;
struct Work{
int j, b;
}w[maxn];
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, kase = 0;
while(scanf("%d", &n)&&n){
For(i,1,n)scanf("%d%d", &w[i].b, &w[i].j);
sort(w+1, w+1+n, [&](Work x, Work y){return x.j>y.j;});
int ans = 0, sum = 0;
For(i,1,n){
sum += w[i].b;
ans = max(ans, sum+w[i].j);
}
printf("Case %d: %d\n", ++kase, ans);
}
return 0;
}