QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134356 | #2281. BnPC | Yarema# | WA | 1ms | 3536kb | C++17 | 1.6kb | 2023-08-03 17:53:02 | 2023-08-03 17:53:03 |
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, LL> m;
FOR (i, 0, n)
{
string s;
cin >> s;
int x;
cin >> x;
m[s] = x;
}
int k;
cin >> k;
map<string, LL> m2;
map<string, LL> cnt;
map<string, VI> m3;
map<string, LL> bal;
LL ans = 0;
FOR (i, 0, k)
{
string s;
LL 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(0ll, 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];
LL 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;
ans += p * mxc;
assert(p >= 0);
assert(ans >= 0);
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3476kb
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'