QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#421542#6532. TradingHI_SNWA 270ms3844kbC++20919b2024-05-25 20:59:522024-05-25 20:59:53

Judging History

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

  • [2024-05-25 20:59:53]
  • 评测
  • 测评结果:WA
  • 用时:270ms
  • 内存:3844kb
  • [2024-05-25 20:59:52]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int T, n;
	cin >> T;
	while(T--){
		cin >> n;
		unsigned long long ans = 0;
		vector<pair<int, unsigned long long> > store(n);
		int a;
		unsigned long long b;
		for(int i = 0; i < n; i++){
			cin >> a >> b;
			store[i] = make_pair(a, b);
		}
		sort(store.begin(), store.end());
		if(store[0].first == store[n-1].first){
			cout << 0 << endl;
			continue;
		}
		int l = 0, r = n - 1;
		while(l < r){
			unsigned long long temp = store[r].first - store[l].first;
			if(store[l].second >= store[r].second){
				ans += store[r].second * temp;
				store[l].second -= store[r].second;
				r--;
			}else{
				ans += store[l].second * temp;
				store[l].second = 0;
				store[r].second -= store[l].second;
			}
			if(!store[l].second)
			    l++;	    
		}
		cout << ans << endl;
	}
	return 0;
}

詳細信息

Test #1:

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

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: 270ms
memory: 3844kb

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:

1281007100160
479759689322
390430341174
1116204445744
1491423573098
791234908004
198954424176
1112399243099
14257598794
1560061838548
643222056804
957665608000
1554922394333
237175705692
0
1297542286789
714985779026
1007082228830
890429329974
1668885341118
819214004462
1258487361357
547471672972
0
1...

result:

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