QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418443#6532. TradingSIGHT#WA 268ms3692kbC++23918b2024-05-23 14:00:342024-05-23 14:00:35

Judging History

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

  • [2024-05-23 14:00:35]
  • 评测
  • 测评结果:WA
  • 用时:268ms
  • 内存:3692kb
  • [2024-05-23 14:00:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
	int n;
	std::cin >> n;
	std::vector<int> a(n), b(n), idx(n);
	for(int i = 0; i < n; i++) std::cin >> a[i] >> b[i];
	for(int i = 0; i < n; i++) idx[i] = i;
	std::sort(idx.begin(), idx.end(), [&](int x, int y) {return a[x] < a[y];});
	ll sum = 0;
	for(auto e : b) sum += e;
	sum /= 2;
	ll ans = 0;
	ll x = 0;
	for(int i = 0; i < n; i++) {
		if(x + b[idx[i]] <= sum) {
			ans -= a[idx[i]] * b[idx[i]];
			x += b[idx[i]];
		}
		else if(x <= sum) {
			ans -= a[idx[i]] * (sum - x);
			break;
		}
	}
	x = 0;
	
	for(int i = n - 1; i >= 0; i--) {
		if(x + b[idx[i]] <= sum) {
			ans += a[idx[i]] * b[idx[i]];
			x += b[idx[i]];
		}
		else if(x <= sum) {
			ans += a[idx[i]] * (sum - x);
			break;
		}
	}
	
	std::cout << ans << '\n';
}
int main()
{
	int t = 1;
	std::cin >> t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 268ms
memory: 3508kb

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:

76564491461
-79710075587
136304232834
136228374656
-31666110664
-210550263920
95875209072
115608118872
18552566090
-20325393308
356643455768
-135430128857
600904625220
-84380727496
0
334984687571
-2039532899
-264268229126
-326866491440
92040757124
-110566874316
-14432037668
-48019525940
0
-465177577...

result:

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