173162025-06-23 13:06:33akososkaBányász RPG (40 pont)cpp17Wrong answer 9/4054ms784 KiB
#include <bits/stdc++.h>

using namespace std;
int a[100001],n,b[100001],elso,utolso;
long long s,xp;

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[a[i]];
    }
    elso=1;
    utolso=100000;
    while(elso<=utolso){
        if(b[elso]==0)elso++;
        else if(elso<=xp){
            s=s+b[elso];
            xp=xp+b[elso];
            elso++;
        }
        else if(b[utolso]==0)utolso--;
        else if(b[utolso]<=elso-xp){
            s=s+2*b[utolso];
            xp=xp+b[utolso];
            utolso--;
        }
        else{
            int q=elso-xp;
            b[utolso]=b[utolso]-q;
            s=s+2*q;
            xp=xp+q;
        }
    }
    cout<<s;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base9/40
1Accepted0/01ms508 KiB
2Wrong answer0/010ms604 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms500 KiB
5Wrong answer0/28ms316 KiB
6Wrong answer0/217ms472 KiB
7Wrong answer0/23ms316 KiB
8Wrong answer0/24ms436 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms508 KiB
12Wrong answer0/31ms500 KiB
13Wrong answer0/42ms352 KiB
14Wrong answer0/41ms316 KiB
15Wrong answer0/232ms540 KiB
16Wrong answer0/241ms784 KiB
17Wrong answer0/235ms688 KiB
18Wrong answer0/254ms652 KiB