QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420296#6525. New HousesDJ_FTL 1ms7740kbC++14896b2024-05-24 16:17:082024-05-24 16:17:09

Judging History

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

  • [2024-05-24 16:17:09]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7740kb
  • [2024-05-24 16:17:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int a[500006],b[500006],c[500006];
vector<int>du,he;
bool cmp(int a,int b){
	return c[a]>c[b];
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		long long sum=0;
		int n,m;
		cin>>n>>m;
		
		int keyiduju=m-n;
		for(int i=1;i<=n;i++){
			cin>>a[i]>>b[i];
			c[i]=b[i]-a[i];
			sum+=a[i];
			if(a[i]<b[i])du.push_back(i);
		//	else he.push_back(i);
		}
		if(n==2&&m>n){
			int sum1=a[1]+a[2];
			int sum2=b[1]+b[2];
			cout<<(sum1>sum2?sum1:sum2)<<endl;
			continue;
		}
		if(n==1){
			cout<<(a[1]>b[1]?a[1]:b[1])<<endl;
			continue;
		}
		if(keyiduju==0)cout<<sum<<endl;
		else{
			int cnt=0;
			sort(du.begin(),du.end(),cmp);
			for(int i=0;i<keyiduju;i++){
				sum-=a[du[i]];
				sum+=b[du[i]];
			}
			cout<<sum<<endl; 
		}
		
	}
		return 0;
	
		
	}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7740kb

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
Time Limit Exceeded

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:

3247545200
3857424915
2653993029
5452510675
5570513606
3488112068
2044500908
1857678917
7922869525
2237593918
8849775018
6122918324
4435392748
9785339948
5513905900
6788494948
10876574432
3704464685
5394298136
5406336000
7942412169
3061389496
4009320797
6959654560
5733117908
974485573
14538983159
88...

result: