QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141175#6532. Tradingcy1999WA 206ms3680kbC++1.1kb2023-08-17 09:11:592023-08-17 09:12:01

Judging History

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

  • [2023-08-17 09:12:01]
  • 评测
  • 测评结果:WA
  • 用时:206ms
  • 内存:3680kb
  • [2023-08-17 09:11:59]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
using namespace std;

int t, n; 

int main() {
	scanf("%d", &t);
	while(t--) {
		map<int, long long> mp;
		scanf("%d", &n);
		long long sum = 0, in = 0, out = 0, cost = 0; 
		//in就是买入的,手上有的商品。 
		//out事卖出的。 
		for(int i=1; i<=n; i++) {
			int a, b; scanf("%d%d", &a, &b);
			mp[a] += b; 
			sum += 1ll*a*b; //首先全给卖了。 
			out += b;
		}
		//啊,,错了。
		//那反过来想,, 
		for(auto it = mp.begin(); it!=mp.end(); it++) {
			long long a = it->first, b = it->second;
			//最优的肯定是最终手上剩0个。 
			out -= b; 
			in += b;//啊对,总之先把现在遍历到的这个减掉。
			if(out>=in) {
				sum -= a*b;
				cost += a*b;
				if(out==in) break;
			} else {
				//这样的话就是减多了。
				out += b;
				in -= b; //加回来先(
				sum -= a*(out-in)/2;
				cost += a*(out-in)/2; 
				break;
			}
		}
		cout<<sum - cost<<endl;
	}
	
	
	return 0;
}

详细

Test #1:

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

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: 206ms
memory: 3680kb

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:

974212656326
422801098045
290923055490
905027520640
1029190811449
678507966352
198954424177
854342493784
14257598795
988991921253
588571689752
736448232232
1193610112068
190497179448
1
931985141715
607845823133
684919543290
764055201744
1066998333316
404829201204
908985930973
518916157132
0
18970544...

result:

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