QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384553#6532. TradingDDTWA 74ms3776kbC++14793b2024-04-10 01:36:552024-04-10 01:36:55

Judging History

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

  • [2024-04-10 01:36:55]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:3776kb
  • [2024-04-10 01:36:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
#define endl '\n'
#define x first
#define y second
typedef long long ll;
typedef pair<int,int> PII;
PII a[100010];
int n,cnt=0;
void solve()
{
	
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d%d",&a[i].x,&a[i].y);	
		cnt+=a[i].y;
	}
	sort(a+1,a+n+1);
	
	int l=1,r=n;
	ll ans=0;
	while(l<r)
	{
		int res=min(a[l].y,a[r].y);
		a[l].y-=res;
		a[r].y-=res;
		ans+=(a[r].x-a[l].x)*res;
		if(a[l].y==0)l++;
		else r--;
	}
	
	printf("%lld\n",ans);
	//cout<<xs-cb<<endl;
}
/*
10 2
20 4
25 
30 7
50 1
*/
int main()
{
	//ios::sync_with_stdio(false);
	//ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;
	scanf("%d",&t);
	while(t--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

100
0

result:

ok 2 number(s): "100 0"

Test #2:

score: -100
Wrong Answer
time: 74ms
memory: 3776kb

input:

100000
8
567091 283679
875020 918237
314684 148083
456411 304598
766056 882388
135371 326501
578773 250140
221306 874117
5
126777 129517
846433 679825
649281 330021
427768 362636
390068 692169
5
657677 231119
941936 991342
901241 15133
660372 970476
698958 209343
10
478657 163635
752788 819629
82110...

output:

-744919867
-2400664259
-1134720638
-1210578816
-1601339592
-96866416
1385928560
3938969176
1372696906
-7440491420
161170200
2008824615
-4685763516
-2776348872
0
-22761517
2255434397
-2275224070
3845990352
1846443908
5397242676
2747831516
-774885684
0
726882555
-2551834687
1629150693
-1888470433
7519...

result:

wrong answer 1st numbers differ - expected: '974212656325', found: '-744919867'