QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49376 | #2281. BnPC | krystofmitka | WA | 2ms | 3540kb | C++ | 3.2kb | 2022-09-20 17:13:37 | 2022-09-20 17:13:40 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
#include <functional>
#include <unordered_map>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
#define O(i) i & 1
#define E(i) !O(i)
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n; cin >> n;
ll k; cin >> k;
unordered_map<string, ll> current;
unordered_map<string, vector<ll>> maxFreq;
while (n--) {
string a; cin >> a;
ll s; cin >> s;
current[a] = s;
maxFreq[a] = vector<ll>(2, 0);
}
ll l; cin >> l;
ll highestFreq = 0;
while(l--) {
string a; cin >> a;
ll t; cin >> t;
maxFreq[a][0] = max(maxFreq[a][0], t);
maxFreq[a][1]++;
if (maxFreq[a][1] > highestFreq) {
highestFreq = maxFreq[a][1];
}
}
ll ans = 0;
priority_queue<ll> q;
for ( const auto &p : current ) {
vector<ll> mxF = maxFreq[p.first];
ll diff = p.second - mxF[0];
if (diff <= 0) {
k = k + diff;
if (mxF[0] * mxF[1] > highestFreq) {
q.push((mxF[0] + 1) * mxF[1]);
}
} else if (diff > 0) {
ans = ans + mxF[0] * mxF[1];
}
if (k < 0) {
cout << '0' << '\n';
return 0;
}
}
while(k > 0 && !q.empty()) {
ans = ans + q.top();
q.pop();
k--;
}
cout << ans + k*highestFreq << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3540kb
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'