Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss11729 - | Accepted | C++11 | 0.000 | 0.000 | 1122 | 4 mins ago |
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, kase=0;
while(cin >> n && n){
vector<pair<int, int>> a, b;
while(n--){
int x, y; cin >> x >> y;
a.push_back({y, x});
}
sort(a.begin(), a.end(), greater<pair<int, int>>());
for(auto p:a) b.push_back({p.Y, p.X});
int res= b[0].X + b[0].Y;
for(int i=1; i<b.size(); i++){
res= max(res, b[i-1].X + b[i].X + b[i].Y);
b[i].X += b[i-1].X;
}
cout<<"Case "<<++kase<<": "<<res<<"\n";
}
}
No comments:
Post a Comment