QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122552#2281. BnPCbatrr#WA 3ms9708kbC++172.9kb2023-07-10 19:04:532023-07-10 19:04:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-10 19:04:56]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9708kb
  • [2023-07-10 19:04:53]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
//#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 300500, LOG = 31, inf = 1e9, mod = 998244353;
const ll INF = 1e18;

int n;
mt19937 rnd(228);
ll k;
ll s;
const int maxN = 1e5 + 10;
string S[maxN];
ll sc[maxN];
map<string, int> mp;
vector<ll> g[maxN];
void solve() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> S[i] >> sc[i];
        mp[S[i]] = i;
//        cout << " ???? " << sc[i] << endl;
    }
    int l;
    cin >> l;
    for (int i = 0; i < l; i++) {
        string x;
        ll st;
        cin >> x >> st;
        assert(mp.count(x));
        int p = mp[x];
        g[p].emplace_back(st);
    }
    vector<pair<ll,ll>> T;
    ll INI = 0;
    for (int i = 0; i < n; i++) {
        if (g[i].empty()) continue;
        sort(g[i].begin(), g[i].end());
        ll MX = g[i].back();

        if (sc[i] < MX) {
            k -= (MX - sc[i]);
            sc[i] = MX;
        }

        //+cnt, +cnt
        if (sc[i] == MX) {
            ll cnt = 0;
            ll add = 0;
            ll S = 0;
            for (ll u : g[i]) {
                if (u < MX) {
                    S += MX;
                    cnt++;
                }
                else {
                    assert(u == MX);
                }
            }
            INI += S;
//            cout << " ADDD " << S << endl;
            add = (MX + 1) * g[i].size() - INI;
            //g[i].size()
            T.emplace_back((ll)g[i].size(), add);
        }
        else {
            assert(sc[i] > MX);
            INI += sc[i] * g[i].size();
//            cout << " ADDD " << sc[i] << " " << g[i].size() << endl;
            T.emplace_back((ll)g[i].size(), (ll)g[i].size());
        }
    }
    if (k < 0) {
        cout << 0 << '\n';
        return ;
    }
    if (k == 0) {
        cout << INI << '\n';
        return;
    }
    ll best = -1e18;
    sort(T.begin(), T.end());
    priority_queue<ll, vector<ll>, greater<>> pq;
    ll CUR_S = 0;
//    cout << INI << " ??? " << endl;
    for (int i = 0; i < T.size(); i++) {
        while (!pq.empty() && pq.size() > k - 1) {
            CUR_S -= pq.top();
            pq.pop();
        }
        while (!pq.empty() && pq.top() < T[i].first) {
            CUR_S -= pq.top();
            pq.pop();
        }
        CUR_S += T[i].second;
        best = max(best, INI + CUR_S + (k - (ll)pq.size() - 1) * T[i].first);
        pq.push(T[i].second);
    }
    cout << best << '\n';
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case #" << i << endl;
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 9708kb

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: -100
Wrong Answer
time: 3ms
memory: 9708kb

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:

414

result:

wrong answer 1st lines differ - expected: '429', found: '414'