QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266969#6525. New Houseschitoge#WA 305ms3792kbC++20821b2023-11-26 20:26:402023-11-26 20:26:41

Judging History

你现在查看的是最新测评结果

  • [2023-11-26 20:26:41]
  • 评测
  • 测评结果:WA
  • 用时:305ms
  • 内存:3792kb
  • [2023-11-26 20:26:40]
  • 提交

answer

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

using pii = pair<int,int>;

bool cmp(pii a,pii b){
	return a.second==b.second?a.first<b.first:a.second>b.second;
}

void solve(){
	int n,m;cin>>n>>m;
	int t=m-n;
	vector<pair<int,int>> arr(n);
	long long ans=0;
	for(int i=0;i<n;i++){
		cin>>arr[i].first>>arr[i].second;
		ans+=arr[i].first;
	}
		
	sort(arr.begin(),arr.end(),cmp);
	long long q=ans;
	for(int i=1;i<=t;i++){
		if(i==n-1){
			q=0;
			for(int j=0;j<n;j++){
				q+=arr[j].second;
//				cout<<q<<' '<<arr[j].second<<' '<<j<<endl;
			}
//			cout<<"QQQQQ"<<ans<<endl;
		}
		else{
			q-=arr[i-1].first;q+=arr[i-1].second;
		}
//			cout<<ans<<' '<<q<<endl;
		ans=max(ans,q);
	}
	cout<<ans<<endl;
}


int main(){
	int tt;cin>>tt;
	while(tt--){
		solve();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3792kb

input:

3
4 5
1 100
100 1
100 1
100 1
2 2
1 10
1 10
2 3
100 50
1 1000

output:

400
2
1050

result:

ok 3 number(s): "400 2 1050"

Test #2:

score: -100
Wrong Answer
time: 305ms
memory: 3524kb

input:

100000
6 11
191141536 365120521
799679686 648574232
102602909 467685128
405440859 796808887
384858152 191995380
433392826 195648471
5 13
831367906 510447872
795639287 575551283
811207605 176441088
240156289 946977042
133416463 721098873
5 5
806744021 699586200
630510306 637827160
49223781 641709297
...

output:

3096439746
4106290713
2653993029
4824603595
5570513606
2031887824
2044500908
1857678917
6712040279
2237593918
6479042694
5393412666
3690874076
5685141393
5513905900
5404435094
4372471266
2381297725
3430587752
4783141742
3865497483
1303747744
2692878616
3833748807
2716183054
850381192
6464787173
8839...

result:

wrong answer 1st numbers differ - expected: '3247545200', found: '3096439746'