QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249903 | #2281. BnPC | Fyind# | WA | 0ms | 3664kb | C++17 | 1.6kb | 2023-11-12 17:43:18 | 2023-11-12 17:43:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
int tot = 0;
map<string, int> m;
vector<int> cur(n + 1);
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
int p;
cin >> p;
if (!m[s])
m[s] = ++tot;
cur[m[s]] = p;
}
int mm;
cin >> mm;
ll ans = 0;
priority_queue<pair<int, int>> q;
vector<pair<int, int>> a(n + 1, {-1, 0});
for (int i = 1; i <= mm; ++i) {
string s;
cin >> s;
int p;
cin >> p;
int id = m[s];
if (a[id].first == -1)
a[id].first = p, a[id].second = 1;
else {
if (a[id].first <= p)
a[id] = {p, a[id].second + 1};
else
++a[id].second;
}
}
ll ss = 0;
for (int i = 1; i <= n; ++i) {
ss += max(0, a[i].first - cur[i]);
ans += 1ll * a[i].first * (a[i].second - 1);
q.push({a[i].first + a[i].second, a[i].second});
}
if (k < ss) {
cout << "0\n";
return 0;
}
k -= ss;
// cout << k << ' ' << ans << endl;
while (k > 0 && !q.empty()) {
auto [v, cnt] = q.top();
q.pop();
if (v == cnt) {
ans += 1ll * v * k;
break;
}
ans += v, q.push({cnt, cnt});
--k;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
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: 0ms
memory: 3564kb
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:
427
result:
wrong answer 1st lines differ - expected: '429', found: '427'