QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#636100 | #2281. BnPC | oxford01# | WA | 0ms | 3744kb | C++20 | 2.4kb | 2024-10-12 22:11:23 | 2024-10-12 22:11:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = a; i < (b); ++i)
#define repr(i, a, b) for (auto i = (a) - 1; i >= (b); --i)
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
#define int long long
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pii>;
template<class T>
inline bool cmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template<class T>
inline bool cmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
const int inf = 0x3f3f3f3f;
const ll linf = 1e18;
const double dinf = numeric_limits<double>::infinity();
signed main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, k;
cin >> n >> k;
map<string, int> cnt;
map<string, pair<int, int>> maxN;
map<string, int> curr;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int val; cin >> val;
curr[s] = val;
}
int l;
cin >> l;
vector<pair<string, int>> queries(l);
for (int i = 0; i < l; i++) {
string s;
cin >> s;
int t;
cin >> t;
queries[i] = {s, t};
cnt[s]++;
if (maxN[s].first < t) {
maxN[s] = {t, 1};
} else if (maxN[s].first == t) {
maxN[s].second++;
}
k -= maxN[s].first-curr[s];
curr[s] = maxN[s].first;
}
if (k <= 0) {
cout << 0 << endl;
return 0;
}
int res = 0;
priority_queue<pair<int, string>> Q;
map<string, int> tmp;
for (int i = 0; i < l; i++) {
if (curr[queries[i].first] > queries[i].second) {
res += curr[queries[i].first];
tmp[queries[i].first]++;
} else {
tmp[queries[i].first]+= queries[i].second;
tmp[queries[i].first]++;
}
}
for (auto [key, value] : tmp) {
Q.push({value, key});
}
while (!Q.empty() && k > 0) {
pair<int, string> arc = Q.top();
Q.pop();
k--;
res += arc.first;
Q.push({cnt[arc.second], arc.second});
}
cout << res << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 3744kb
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:
431
result:
wrong answer 1st lines differ - expected: '429', found: '431'