QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#198762#2281. BnPCBeevo#WA 1ms3444kbC++201.7kb2023-10-03 17:07:332023-10-03 17:07:33

Judging History

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

  • [2023-10-03 17:07:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3444kb
  • [2023-10-03 17:07:33]
  • 提交

answer

#include <bits/stdc++.h>

#define el '\n'

typedef long long ll;
typedef long double ld;

#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void testCase() {
    ll k;
    int n;
    cin >> n >> k;

    int a;
    string s;
    map<string, int> mp;
    for (int i = 0; i < n; i++)
        cin >> s >> a, mp[s] = a;

    int l;
    cin >> l;

    map<string, int> mx, freq, mxFreq;
    for (int i = 0; i < l; i++) {
        cin >> s >> a;

        if (a != mx[s])
            mx[s] = a, mxFreq[s] = 1;
        else if (a == mx[s])
            mxFreq[s]++;

        freq[s]++;
    }

    ll sol = 0;
    for (auto &i: mx) {
        if (mp[i.first] <= i.second) {
            k -= i.second - mp[i.first];

            sol += 1LL * i.second * (freq[i.first] - mxFreq[i.first]);
        }
        else
            sol += 1LL * mp[i.first] * freq[i.first];
    }

    if (k < 0)
        return cout << 0, void();

    set<string> vis;
    set<pair<ll, string>, greater<>> st;
    for (auto &i: mx) {
        if (mp[i.first] <= i.second)
            st.emplace(1LL * (i.second + 1) * mxFreq[i.first] + freq[i.first] - mxFreq[i.first], i.first);
        else
            st.emplace(freq[i.first], i.first);
    }

    while (vis.find(st.begin()->second) == vis.end() && k) {
        k--;

        auto p = *st.begin();

        sol += p.first;

        vis.insert(p.second);

        st.erase(st.begin());

        st.emplace(freq[p.second], p.second);
    }

    sol += 1LL * k * st.begin()->first;

    cout << sol;
}

signed main() {
    Beevo

    int t = 1;
//    cin >> t;

    while (t--)
        testCase();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3444kb

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:

85

result:

wrong answer 1st lines differ - expected: '82', found: '85'