QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134278 | #2281. BnPC | Yarema# | WA | 1ms | 3536kb | C++17 | 1.6kb | 2023-08-03 16:16:44 | 2023-08-03 16:16:47 |
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;
map<string, VI> m3;
map<string, LL> bal;
LL ans = 0;
FOR (i, 0, k)
{
string s;
int x;
cin >> s >> x;
m3[s].PB(x);
if (m2.count(s)) m2[s] = max(m2[s], x);
else m2[s] = x;
cnt[s]++;
}
for (auto [s, x] : m2)
{
for (auto a : m3[s])
{
if (a < x)
{
bal[s] += x;
ans += x;
}
}
}
LL need = 0;
for (auto [s, x] : m2)
need += max(0, x - m[s]);
if (need > p)
{
cout << 0 << '\n';
return 0;
}
p -= need;
vector<LL> v;
for (auto [s, x] : m2)
{
LL y = LL(x + 1) * cnt[s] - bal[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: 100
Accepted
time: 1ms
memory: 3488kb
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: 3536kb
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'