QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#23778 | #2281. BnPC | galaxias# | WA | 4ms | 5692kb | C++14 | 2.0kb | 2022-03-19 13:51:42 | 2022-04-30 04:07:37 |
Judging History
answer
//
// Created by onglu on 2022/3/19.
//
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define endl '\n'
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define Mid ((l + r) / 2)
#define int long long
using namespace std;
const int N = 2e6 + 1009;
//const int N = 2e5 + 1009;
//const int N = 5009;
//const int N = 309
map<string, int> M;
struct task {
int id, cnt, maxn;
} a[N];
int n, m;
int scr[N], maxcnt;
void work() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
string s;
cin >> s;
M[s] = i;
cin >> scr[M[s]];
a[i].id = i;
}
int q;
cin >> q;
while(q--) {
string s;
int x;
cin >> s >> x;
a[M[s]].maxn = max(a[M[s]].maxn, x);
a[M[s]].cnt++;
maxcnt = max(maxcnt, a[M[s]].cnt);
}
int ans = 0;
for(int i = 1; i <= n; i++) {
if(a[i].maxn < scr[i]) {
ans += scr[i] * a[i].cnt;
a[n].id = i;
swap(a[n], a[i]);
swap(scr[i], scr[n]);
n--;
i--;
} else {
m -= a[i].maxn - scr[i];
scr[i] = a[i].maxn;
}
}
if(m < 0) {
cout << 0 << endl;
return ;
}
sort(a + 1, a + 1 + n, [](const task &a, const task &b) {
return (scr[a.id] + 1) * a.cnt > (scr[b.id] + 1) * b.cnt;
});
for(int i = 1; i <= n && m > 0; i++) {
if((scr[a[i].id] + 1) * a[i].cnt >= maxcnt) {
ans += (scr[a[i].id] + 1) * a[i].cnt;
m -= 1;
} else {
break;
}
}
ans += m * maxcnt;
cout << ans << endl;
}
signed main() {
#ifdef LOCAL
freopen("C:\\Users\\onglu\\CLionProjects\\acm\\data.in", "r", stdin);
freopen("C:\\Users\\onglu\\CLionProjects\\acm\\data.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 5692kb
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:
80
result:
wrong answer 1st lines differ - expected: '82', found: '80'