QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#249909 | #2281. BnPC | Fyind# | WA | 1ms | 3464kb | C++17 | 1.6kb | 2023-11-12 17:52:32 | 2023-11-12 17:52:33 |
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);
ll n, k;
cin >> n >> k;
ll tot = 0;
map<string, ll> m;
vector<ll> cur(n + 1);
for (ll i = 1; i <= n; ++i) {
string s;
cin >> s;
ll p;
cin >> p;
if (!m[s])
m[s] = ++tot;
cur[m[s]] = p;
}
ll mm;
cin >> mm;
ll ans = 0;
priority_queue<pair<ll, ll>> q;
vector<pair<ll, ll>> a(n + 1, {-1, 0});
vector<map<ll, ll>> kkk(n + 1);
for (ll i = 1; i <= mm; ++i) {
string s;
cin >> s;
ll p;
cin >> p;
ll 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;
}
++kkk[id][p];
}
ll ss = 0;
for (ll i = 1; i <= n; ++i) {
ss += max(0ll, a[i].first - cur[i]);
ans += 1ll * a[i].first * (a[i].second - kkk[i][a[i].first]);
q.push({a[i].first * kkk[i][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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3464kb
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: 1ms
memory: 3408kb
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'