QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19596 | #2281. BnPC | JohnAlfnov | TL | 251ms | 22084kb | C++20 | 1.4kb | 2022-02-06 12:13:21 | 2022-05-06 06:14:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct apple{
long long X;
int Y;
apple(long long X=0,int Y=0):X(X),Y(Y){}
bool operator<(const apple &other)const{
return X>other.X;
}
}e[100005];
map<string,pair<multiset<int>,int>>mp;
string a[100005];
int b[100005];
long long s[100005];
int main(){
int n;
long long m;
cin>>n>>m;
for(int i=1;i<=n;++i)cin>>a[i]>>b[i];
int q;
cin>>q;
for(int i=1;i<=q;++i){
string a;
int b;
cin>>a>>b;
auto at=mp[a];
at.first.emplace(b);
++at.second;
mp[a]=at;
}
long long ans=0;
int tot=0;
for(int i=1;i<=n;++i){
if(!mp.count(a[i]))continue;
auto at=mp[a[i]];
int mx=0,gs=0;
for(auto cu:at.first)mx=max(mx,cu);
for(auto cu:at.first)if(cu!=mx)++gs;
if(b[i]<=mx){
m-=mx-b[i];
b[i]=mx;
ans+=1ll*b[i]*gs;
e[++tot]=apple(1ll*(b[i]+1)*(at.second-gs)+gs,at.second);
}else{
ans+=1ll*b[i]*at.second;
e[++tot]=apple(at.second,at.second);
}
}
if(m<0){
printf("0\n");
return 0;
}
sort(e+1,e+tot+1);
long long aa=0;
for(int i=1;i<=tot;++i)s[i]=s[i-1]+e[i].X;
for(int i=1;i<=tot;++i){
if(!m)continue;
int wz=lower_bound(e+1,e+tot+1,apple(e[i].Y,0))-e-1;
if(wz>=i&&m>=i)wz=min(0ll+wz,m),aa=max(aa,s[wz]+1ll*(m-wz)*e[i].Y);
else wz=min(0ll+wz,m-1),aa=max(aa,s[wz]+e[i].X+1ll*(m-wz-1)*e[i].Y);
}
cout<<ans+aa<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 8228kb
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: 0
Accepted
time: 2ms
memory: 9512kb
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:
429
result:
ok single line: '429'
Test #3:
score: 0
Accepted
time: 10ms
memory: 9032kb
input:
5 20 A 100 B 200 C 300 D 400 E 500 949 A 39 A 23 C 163 A 98 B 36 A 3 A 52 B 152 B 167 B 65 C 142 B 66 B 117 C 288 C 155 E 341 A 97 D 173 E 31 A 62 D 90 E 361 A 42 D 85 E 1 C 141 B 77 B 194 D 221 E 203 D 345 E 48 B 26 D 46 B 74 E 380 B 181 C 243 B 112 A 99 E 403 C 20 E 453 C 149 B 26 E 245 A 74 D 304...
output:
285180
result:
ok single line: '285180'
Test #4:
score: 0
Accepted
time: 4ms
memory: 8324kb
input:
2 1 A 10 B 12 3 A 10 B 10 B 10
output:
35
result:
ok single line: '35'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8256kb
input:
1 1 OVERENTHUSIASTICNESS 41 1 OVERENTHUSIASTICNESS 0
output:
42
result:
ok single line: '42'
Test #6:
score: 0
Accepted
time: 251ms
memory: 22084kb
input:
100000 1000000000 A 1000000000 B 1000000000 C 1000000000 D 1000000000 E 1000000000 F 1000000000 G 1000000000 H 1000000000 I 1000000000 J 1000000000 K 1000000000 L 1000000000 M 1000000000 N 1000000000 O 1000000000 P 1000000000 Q 1000000000 R 1000000000 S 1000000000 T 1000000000 U 1000000000 V 1000000...
output:
100007999593560
result:
ok single line: '100007999593560'
Test #7:
score: 0
Accepted
time: 238ms
memory: 21772kb
input:
100000 1000000000 A 1000000000 B 1000000000 C 1000000000 D 1000000000 E 1000000000 F 1000000000 G 1000000000 H 1000000000 I 1000000000 J 1000000000 K 1000000000 L 1000000000 M 1000000000 N 1000000000 O 1000000000 P 1000000000 Q 1000000000 R 1000000000 S 1000000000 T 1000000000 U 1000000000 V 1000000...
output:
100006999854911
result:
ok single line: '100006999854911'
Test #8:
score: -100
Time Limit Exceeded
input:
1 1000000000 A 1000000000 100000 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0 A 0...