AOAPC:Chapter1Example2 (UVa 11729)

#include "bits/stdc++.h"
using namespace std;

int n, b, j, kase = 1;

int main(int argc, char const *argv[]) {
  while (scanf("%d", &n), n) {
    vector< pair<int, int> > v;
    for (size_t i = 0; i < n; ++i) {
      scanf("%d%d", &b, &j);
      v.push_back(make_pair(j, b));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int res = 0, s = 0;
    for (size_t i = 0; i < n; ++i) {
      s += v[i].second;
      res = max(res, s + v[i].first);
    }
    printf("Case %d: %d\n", kase++, res);
  }
  return 0;
}

你可能感兴趣的:(Algorithm,ACM-00)