QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698100#6532. Trading0x3fffffffWA 72ms3904kbC++231.0kb2024-11-01 17:23:272024-11-01 17:23:29

Judging History

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

  • [2024-11-01 17:23:29]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:3904kb
  • [2024-11-01 17:23:27]
  • 提交

answer

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

void solve() {
    int n;
    cin >> n;
    vector<array<int, 2>>a(n + 1);
    int cnt = 0;
    for (int i = 1;i <= n;i++) {
        cin >> a[i][0] >> a[i][1];
        cnt += a[i][1];
    }
    sort(a.begin() + 1, a.end());
    // for (int i = 1;i <= n;i++) {
        // cout << a[i][0] << " " << a[i][1] << "\n";
    // }
    int x = cnt / 2;
    int s = 0;
    for (int i = 1;i <= n;i++) {
        int t = min(x, a[i][1]);
        // cout << t << "\n";
        s -= t * a[i][0];
        a[i][1] -= t;
        x -= t;
    }

    x = cnt / 2;
    for (int i = n;i >= 1;i--) {
        int t = min(x, a[i][1]);
        s += t * a[i][0];
        a[i][1] -= t;
        x -= t;
    }
    cout << s << "\n";

}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 72ms
memory: 3904kb

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:

-744919867
1894303037
-1134720638
-1210578816
-1601339592
-96866416
1385928560
-355998120
1372696906
1149443172
161170200
2008824615
-390796220
1518618424
0
-22761517
-2039532899
2019743226
-448976944
1846443908
1102275380
-1547135780
-774885684
0
726882555
1743132609
1629150693
-1888470433
75192932...

result:

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