QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691722#6532. Tradingshabi666#WA 72ms3620kbC++201.1kb2024-10-31 12:45:112024-10-31 12:45:12

Judging History

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

  • [2024-10-31 12:45:12]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:3620kb
  • [2024-10-31 12:45:11]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;

void solve() {
    int n;
    cin >> n;
    vector<PII> v(n);
    int cnt = 0, tot = 0;
    for (auto &[a, b] : v) {
        cin >> a >> b;
        cnt += b;
        tot += a * b;
    }
    sort(v.begin(), v.end());
    int cnt1 = 0, tot1 = 0, flg;
    for (int i = 0; i < (int)v.size(); i++) {
        auto [a, b] = v[i];
        if ( cnt1 + b < cnt / 2 ) {
            cnt1 += b;
            tot1 += a * b;
        } else {
            if ( cnt1 + b < cnt / 2 ) {
                flg = a;
            } else {
                flg = v[i + 1].x;
            }
            tot1 += a * ( cnt / 2 - cnt1 );
            cnt1 = cnt / 2;
            break;
        }
    }
    if ( cnt % 2 == 0 ) flg = 0;
    cout << tot - 2 *  tot1 - flg << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
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: 72ms
memory: 3620kb

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:

974212469042
422801098045
290922853207
905027520640
1029190239998
678507966352
198953880640
854342493784
14258242321
988991764926
588571689752
736448156294
1193610112068
190497131293
961239
931985141715
607845823133
684919543290
764055201744
1066998333316
404829201204
908985921332
518916157132
0
189...

result:

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