QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266767#6532. Tradingchitoge#TL 1ms3472kbC++20651b2023-11-26 17:29:202023-11-26 17:29:21

Judging History

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

  • [2023-11-26 17:29:21]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3472kb
  • [2023-11-26 17:29:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
struct node {
	int a, b;
	bool operator < (const node &a) const {
		return this -> a < a.a;
	}
};
void solve() {
	int n;
	cin >> n;
	vector<node> item(n);
	for(auto &[x , y] : item) {
		cin >> x >> y;
	}
	sort(item.begin() , item.end());
	int l = 0 , r = n - 1;
	ll ans = 0;
	while(l <= r) {
		ans += item[r].a - item[l].a;
		--item[r].b;
		--item[l].b;
		if(item[l].b <= 0) ++l;
		if(item[r].b <= 0) --r;
	}
	cout << ans << '\n';
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt;
	cin>>tt;
	while(tt--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3472kb

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
Time Limit Exceeded

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:


result: