QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#141319#6525. New Housescy1999WA 1ms3400kbC++20737b2023-08-17 10:43:342023-08-17 10:43:38

Judging History

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

  • [2023-08-17 10:43:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3400kb
  • [2023-08-17 10:43:34]
  • 提交

answer

#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=5e5+10;
int t,n,m,ans;
struct node{
	int a,b;
}s[N];
bool cmp(node a,node b){
	return a.b-a.a>b.b-b.a;
}
signed main(){
	cin>>t;
	while(t--){
		cin>>n>>m;
		
		for(int i=1;i<=n;i++)
			cin>>s[i].a>>s[i].b;
		sort(s+1,s+1+n,cmp);
		
		int mid=1;
		while(mid<=n&&s[mid].b>s[mid].a)mid++;
		mid--;
		
		int tmp=m-mid*2-(n-mid)+(n==mid);
		mid-=max(0ll,0-tmp);
		
		if(mid==n-1)
			if(s[n].a+s[n-1].a>s[n].b+s[n-1].b)
				mid--;
				
		ans=0;
		for(int i=1;i<=mid;i++)
			ans+=s[i].b;
		for(int i=mid+1;i<=n;i++)
			if(n>mid+1)
				ans+=s[i].a;
			else
				ans+=s[i].b;
		cout<<ans<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3400kb

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
20
1050

result:

wrong answer 2nd numbers differ - expected: '2', found: '20'