表示cin很不靠谱,10^5的数据量都能TLE 改成scanf 300+ms。
My Code:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <fstream>
using namespace std;
const int N = 100005;
class phage{
public:
int di;
int ti;
}p[N];
bool cmp(phage a, phage b){
if(a.ti != b.ti) return a.ti > b.ti;
else return a.di > b.di;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("data.in", "r", stdin);
#endif
int T, n, i, sum, tmp, ca = 0;
cin >> T;
while(T--){
cin >> n;
for(i = 0; i < n; i++){
scanf("%d%d", &p[i].di, &p[i].ti);
}
sort(p, p + n, cmp);
sum = 0; tmp = 0;
for(i = 0; i < n; i++){
tmp += p[i].di;
if(tmp + p[i].ti > sum){
sum = tmp + p[i].ti;
}
}
cout << "Case " << ++ca << ": " << sum << endl;
}
return 0;
}