QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212059 | #2281. BnPC | tikara | WA | 1ms | 3872kb | C++14 | 2.0kb | 2023-10-13 06:59:55 | 2023-10-13 06:59:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
map<string, int> att;
for(int i = 0; i < n; ++i){
string s; int a;
cin >> s >> a;
att[s] = a;
}
int l; cin >> l;
vector<pair<string, int>> inp(l);
map<string, int> ev;
map<string, int> needs;
map<string, int> max_pt;
map<string, int> vis;
for(int i = 0; i < l; ++i){
string s; int a;
cin >> s >> a;
inp[i] = {s, a};
int need = a - att[s];
needs[s] = max(need, needs[s]);
ev[s]++;
max_pt[s] = max(max_pt[s], a);
vis[s] = 0;
// ev[s] = max(ev[s], need);
}
for(auto [a, b] : needs){
// cout << a << ' ' << b << endl;
k -= b;
att[a] += b;
}
if(k <= 0) {
cout << 0 << endl;
return 0;
}
vector<tuple<ll, ll, string>> points;
// cout << endl;
for(auto [a, b] : att){
// cout << a << ' ' << max_pt[a] << ' ' << ev[a] << ' ' << b << endl;
// cout << (max_pt[a]+1)*ev[a] << endl;
if(att[a] == max_pt[a])
points.push_back({(max_pt[a]+1)*ev[a], 0, a});
points.push_back({ev[a], 1, a});
}
sort(points.rbegin(), points.rend());
int i = 0;
ll ans = 0;
while(k > 0){
auto [pt, type, st] = points[i];
// cout << pt << ' ' << type << ' ' << st << endl;
if(type == 0){
ans += pt;
k--;
} else {
ans += (pt*k);
k = 0;
}
vis[st] = 1;
i++;
}
for(int i = 0; i < l; ++i){
// cout << vis[inp[i].first] << ' ' << inp[i].second << ' ' << max_pt[inp[i].first] << endl;
if(!vis[inp[i].first] && inp[i].second != att[inp[i].first]){
// cout << "ue" << endl;
ans += att[inp[i].first];
}
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 3604kb
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: -100
Wrong Answer
time: 1ms
memory: 3872kb
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:
245380
result:
wrong answer 1st lines differ - expected: '285180', found: '245380'