QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226232#2281. BnPCobssWA 266ms35492kbC++171.8kb2023-10-25 18:46:072023-10-25 18:46:07

Judging History

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

  • [2023-10-25 18:46:07]
  • 评测
  • 测评结果:WA
  • 用时:266ms
  • 内存:35492kb
  • [2023-10-25 18:46:07]
  • 提交

answer

#include <bits/stdc++.h>
// #define tests
#define int long long
const int N = 1e5 + 10;
using namespace std;
using LL = long long;

void solve() {
    int n, k;
    cin >> n >> k;
    map<string, int> mp1, mp2, mp3;
    for(int i = 1; i <= n; i++) {
        string s;
        int x;
        cin >> s >> x;
        mp1[s] = x;
    } 
    int m;
    cin >> m;
    map<string, vector<int>> v;
    for(int i = 1; i <= m; i++){
        string s;
        int x;
        cin >> s >> x;
        v[s].push_back(x);
        mp2[s] = max(mp2[s], x); //xiaohao
    }

    int sum1 = 0, sum2 = 0;
    for(auto [x, y] : mp2) {
        sum1 += mp1[x];
        sum2 += y;
    }

    if(sum2 >= sum1 + k){
        cout << 0;
        return;
    }

    for(auto &[x, y] : mp1){
        if(y <= mp2[x]) {
            k -= mp2[x] - y;
            y = mp2[x];
        }
    }

    int maxv = 0;
    map<string, int> d;
    for(auto [s, vv] : v){
        maxv = max(maxv, (int)vv.size());
        for(auto x : vv){
            if(mp1[s] > x) d[s] ++;
            else d[s] += mp1[s] + 1;
        }
    }
    
    priority_queue<pair<int,string>> q;
    for(auto [s, x] : d) q.push({x, s});
    
    while(q.size() && k && q.top().first >= maxv){
        auto [x, y] = q.top();
        mp1[y] ++;
        q.pop();
        k --;   
    }

    for(auto [s, vv] : v){
        if(vv.size() == maxv) mp1[s] += k;
    }
    
    int ans = 0;
    for(auto [s, vv] : v){
        for(auto x : vv){
            if(mp1[s] > x) ans += mp1[s];
        }
    }
    cout << ans << '\n';
}

signed main() {
    cin.tie(0)->ios::sync_with_stdio(0);
    cout.tie(0);

    int t = 1;
#ifdef tests
    cin >> t;
#endif
    for(int _ = 1; _ <= t; _ ++) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 14
THISISTHEONE 8
B 0
C 0
8
THISISTHEONE 10
C 0
B 1
B 0
THISISTHEONE 0
C 1
THISISTHEONE 0
THISISTHEONE 0

output:

82

result:

ok single line: '82'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

3 99
THEFIRSTINCREASE 6
SECONDINCREASE 4
ZZZ 1
9
THEFIRSTINCREASE 4
ZZZ 0
THEFIRSTINCREASE 6
SECONDINCREASE 8
THEFIRSTINCREASE 2
SECONDINCREASE 1
ZZZ 0
SECONDINCREASE 8
THEFIRSTINCREASE 3

output:

429

result:

ok single line: '429'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

5 20
A 100
B 200
C 300
D 400
E 500
949
A 39
A 23
C 163
A 98
B 36
A 3
A 52
B 152
B 167
B 65
C 142
B 66
B 117
C 288
C 155
E 341
A 97
D 173
E 31
A 62
D 90
E 361
A 42
D 85
E 1
C 141
B 77
B 194
D 221
E 203
D 345
E 48
B 26
D 46
B 74
E 380
B 181
C 243
B 112
A 99
E 403
C 20
E 453
C 149
B 26
E 245
A 74
D 304...

output:

285180

result:

ok single line: '285180'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

2 1
A 10
B 12
3
A 10
B 10
B 10

output:

35

result:

ok single line: '35'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

1 1
OVERENTHUSIASTICNESS 41
1
OVERENTHUSIASTICNESS 0

output:

42

result:

ok single line: '42'

Test #6:

score: 0
Accepted
time: 266ms
memory: 35492kb

input:

100000 1000000000
A 1000000000
B 1000000000
C 1000000000
D 1000000000
E 1000000000
F 1000000000
G 1000000000
H 1000000000
I 1000000000
J 1000000000
K 1000000000
L 1000000000
M 1000000000
N 1000000000
O 1000000000
P 1000000000
Q 1000000000
R 1000000000
S 1000000000
T 1000000000
U 1000000000
V 1000000...

output:

100007999593560

result:

ok single line: '100007999593560'

Test #7:

score: -100
Wrong Answer
time: 249ms
memory: 34464kb

input:

100000 1000000000
A 1000000000
B 1000000000
C 1000000000
D 1000000000
E 1000000000
F 1000000000
G 1000000000
H 1000000000
I 1000000000
J 1000000000
K 1000000000
L 1000000000
M 1000000000
N 1000000000
O 1000000000
P 1000000000
Q 1000000000
R 1000000000
S 1000000000
T 1000000000
U 1000000000
V 1000000...

output:

100076997881191

result:

wrong answer 1st lines differ - expected: '100006999854911', found: '100076997881191'