QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622515 | #2541. Coins and Boxes | ucup-team3474# | WA | 1ms | 6036kb | C++20 | 1.1kb | 2024-10-08 22:14:02 | 2024-10-08 22:14:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=214514;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,a[N],b[N];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%lld",&b[i]);
}
vector<PII> v;
for(int i=1;i<=n;i++) v.push_back({a[i],-1});
for(int i=1;i<=n;i++) v.push_back({b[i],1});
sort(v.begin(),v.end());
ll now=0,val=0;
int i=0,j=0;
ll ans=0;
while(i<v.size()){
// cout<<i<<" "<<j<<" "<<val<<endl;
now+=v[i].second;
i++;
while(now!=0){
now+=v[i].second;
i++;
}
if(v[j].second==1){
ans+=v[i-1].first-val;
val=v[i-1].first;
}else{
ll ad=v[i-1].first-val+v[i-1].first-v[j].first;
// cout<<ad<<endl;
if(i!=v.size()) ad+=v[i-1].first-v[j].first;
// cout<<ad<<endl;
ans+=ad;
val=v[i-1].first;
}
j=i;
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6036kb
input:
4 1 6 7 12 3 5 10 11
output:
22
result:
wrong answer expected '21', found '22'