QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19592 | #2281. BnPC | JohnAlfnov | WA | 2ms | 8288kb | C++20 | 1.2kb | 2022-02-06 12:05:15 | 2022-05-06 06:13:44 |
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<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=max(at.first,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]];
if(b[i]<=at.first){
m-=at.first-b[i];
b[i]=at.first;
e[++tot]=apple(1ll*(b[i]+1)*at.second,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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8288kb
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'