UVA - 11729

作为一名程序员,再怎么忙,也不应忘了算法啊。休息的时候学学吧,让自己爱上算法!

CPP:

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 10000 + 7;

struct Employee {
  int b;
  int j;
  bool operator < (const Employee A) const {
    if(j == A.j) {
      return b < A.b;
    }
    else {
      return j > A.j;
    }
  }
} em[maxn];

int main() {
//  freopen("E:1.in", "r", stdin);
  int n, K = 0;
  while(scanf("%d",&n)==1&&n) {
    for(int i=0;i<n;i++) {
      scanf("%d%d",&em[i].b,&em[i].j);
    }
    sort(em, em+n);
    int ans = 0, sumB = 0;
    for(int i=0;i<n;i++) {
      sumB += em[i].b;
      ans = max(ans, sumB + em[i].j);
    }
    printf("Case %d: %d\n",++K ,ans);
  }
  return 0;
}
posted @ 2018-03-21 14:43  wen98y  阅读(93)  评论(1编辑  收藏  举报