QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622515#2541. Coins and Boxesucup-team3474#WA 1ms6036kbC++201.1kb2024-10-08 22:14:022024-10-08 22:14:03

Judging History

你现在查看的是最新测评结果

  • [2024-10-08 22:14:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6036kb
  • [2024-10-08 22:14:02]
  • 提交

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'