QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134244 | #2281. BnPC | PetroTarnavskyi# | WA | 1ms | 3532kb | C++17 | 2.2kb | 2023-08-03 15:25:50 | 2023-08-03 15:25:51 |
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;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
map<string, int> have;
FOR(i, 0, n){
string s;
int val;
cin >> s >> val;
have[s] = val;
}
int m;
cin >> m;
map<string, VI> need;
FOR(i, 0, m){
string s;
int cnt;
cin >> s >> cnt;
need[s].PB(cnt);
assert(have.count(s));
}
LL sum = 0;
LL ans = 0;
vector<pair<LL, LL>> to_add;
for(auto it : have){
int cur = it.S;
VI vals = need[it.F];
vals.PB(0);
sort(ALL(vals));
int cntmx = 0;
while(cntmx < SZ(vals) && vals[SZ(vals) - cntmx - 1] == vals.back())
cntmx++;
if(cur > vals.back())
to_add.PB(MP(0, SZ(vals) - 1));
else
to_add.PB(MP(1LL * cntmx * vals.back(), SZ(vals) - 1));
ans += 1LL * vals.back() * (SZ(vals) - 1);
ans -= to_add.back().F;
sum += max(0, vals.back() - cur);
}
if(sum > k){
cout << "0\n";
return 0;
}
sort(ALL(to_add));
reverse(ALL(to_add));
assert(SZ(to_add) == n);
VI has_cnt(m + 1, 0);
FOR(i, 0, SZ(to_add))
has_cnt[to_add[i].S] = 1;
k -= sum;
LL res = ans;
FOR(cnt, 1, m + 1){
if(has_cnt[cnt] == 0 || k == 0)
continue;
LL cur = ans;
LL cur_k = k;
LL mx = 0;
FOR(i, 0, n){
if(cur_k == 0)
break;
bool take = 0;
if(mx < cnt && cur_k == 1){
if(to_add[i].S >= cnt)
take = 1;
}else{
if(to_add[i].F + to_add[i].S >= cnt)
take = 1;
}
if(take){
cur += to_add[i].F + to_add[i].S;
cur_k -= 1;
mx = max(mx, to_add[i].S);
// cout << i << endl;
}
}
assert(mx >= cnt);
//cout << cur << " " << cur_k << " " << mx << endl;
cur += 1LL * cur_k * mx;
res = max(res, cur);
}
cout << res << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3484kb
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: 3532kb
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'