173152025-06-23 13:06:01akososkaBányász RPG (40 pont)cpp17Wrong answer 0/4054ms1588 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=100001;
    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
base0/40
1Wrong answer0/01ms500 KiB
2Wrong answer0/010ms564 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/28ms592 KiB
6Wrong answer0/217ms820 KiB
7Wrong answer0/23ms316 KiB
8Wrong answer0/24ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/31ms316 KiB
11Wrong answer0/31ms412 KiB
12Wrong answer0/31ms656 KiB
13Wrong answer0/42ms316 KiB
14Wrong answer0/42ms544 KiB
15Wrong answer0/232ms1148 KiB
16Wrong answer0/241ms1332 KiB
17Wrong answer0/235ms1336 KiB
18Wrong answer0/254ms1588 KiB