QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#421518#6530. Programming ContestHI_SNWA 1ms3580kbC++20919b2024-05-25 20:32:012024-05-25 20:32:01

Judging History

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

  • [2024-05-25 20:32:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2024-05-25 20:32:01]
  • 提交

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: 0
Wrong Answer
time: 1ms
memory: 3580kb

input:

4
2003
1 2020
2023
2003
1 2020
2003
2345
0
3456
3000
4 3001 3003 3004 3008
3007

output:

26888834
0
0
0

result:

wrong answer 1st numbers differ - expected: '20', found: '26888834'