AOAPC:Chapter1Example2 (UVa 11729)

来源:互联网 发布:人工智能百度云资源 编辑:程序博客网 时间:2024/06/10 22:50
#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;}
0 0
原创粉丝点击