QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141070#6532. Tradingcy1999WA 1ms3668kbC++749b2023-08-17 08:37:272023-08-17 08:38:08

Judging History

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

  • [2023-08-17 08:38:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3668kb
  • [2023-08-17 08:37:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{
    int a,b;
    friend bool operator<(node a,node b){
    	return a.a<b.a;
    }
}p[1000005];
int n,t,sum,r1,r2,nw;
signed main(){
	cin>>t;
	while(t--){
		cin>>n;sum=0;
		for(int i=1;i<=n;i++){
			scanf("%lld%lld",&p[i].a,&p[i].b);
			sum+=p[i].b;
		}
		sort(p+1,p+n+1);nw=0;r1=r2=0;
		for(int i=1;i<=n;i++){
			if(p[i].b+nw<=sum/2){
				nw+=p[i].b;
				r1+=p[i].a*p[i].b;
			}else{
				r1+=(sum/2-nw)*p[i].a;
				break;
			}
		}
		nw=0;
		for(int i=n;i>=1;i--){
			if(p[i].b+nw<=sum/2){
				nw+=p[i].b;
				r2+=p[i].a*p[i].b;
			}else{
				r2+=(sum/2-nw)*p[i].a;
				break;
			}
		}
		printf("%lld\n",r2-r1);
		return 0;
	}
}

详细

Test #1:

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

input:

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

output:

100

result:

wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements