QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134267 | #2281. BnPC | Yarema# | WA | 0ms | 3452kb | C++17 | 1.4kb | 2023-08-03 16:06:14 | 2023-08-03 16:06:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 1e9 + 7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
LL n, p;
cin >> n >> p;
map<string, int> m;
FOR (i, 0, n)
{
string s;
cin >> s;
int x;
cin >> x;
m[s] = x;
}
int k;
cin >> k;
map<string, int> m2;
map<string, int> cnt;
FOR (i, 0, k)
{
string s;
int x;
cin >> s >> x;
if (m2.count(s)) m2[s] = max(m2[s], x);
else m2[s] = x;
cnt[s]++;
}
LL need = 0;
for (auto [s, x] : m2)
need += max(0, x - m[s]);
if (need >= p)
{
cout << 0 << '\n';
return 0;
}
p -= need;
LL ans = 0;
vector<LL> v;
for (auto [s, x] : m2)
{
LL y = LL(x + 1) * cnt[s];
v.PB(y);
}
sort(ALL(v), greater());
n = min(LL(SZ(v)), p);
FOR (i, 0, n)
ans += v[i];
int mxc = 0;
for (auto [s, x] : cnt)
mxc = max(mxc, x);
RFOR (i, n, 0)
{
if (v[i] < mxc)
{
ans -= v[i];
ans += mxc;
}
}
p -= n;
cout << ans + p * mxc << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3452kb
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'