QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141284#6532. Tradingcy1999WA 1ms3468kbC++20834b2023-08-17 10:15:172023-08-17 10:15:20

Judging History

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

  • [2023-08-17 10:15:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3468kb
  • [2023-08-17 10:15:17]
  • 提交

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){
	if(a.b>a.a&&b.b>b.a)
		return a.b-a.a>b.b-b.a;
	if(a.b>a.a&&b.b<=b.a)
		return 1;
	if(a.b<=a.a&&b.b>b.a)
		return 0;
	return a.a>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(s[mid].b>s[mid].a)mid++;
		mid--;
		int tmp=m-mid*2-(n-mid);
		mid-=max(0ll,0-tmp);
		ans=0;
		if(mid==n-1){
			if(s[n].a+s[n-1].a>s[n].b+s[n-1].b)
				mid--;
		}
		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;
}

詳細信息

Test #1:

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

input:

2
4
10 2
30 7
20 4
50 1
2
1 100
1 1000

output:

102
1052

result:

wrong answer 1st numbers differ - expected: '100', found: '102'