155872025-02-20 19:09:40999Bányász RPG (40 pont)cpp17Wrong answer 3/4065ms1776 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int INF = 1e12;

signed main() {
    int n;cin>>n;
    vector<pair<int,int>> v(n);
    for(auto&[i,j]:v)cin>>i;
    for(auto&[i,j]:v)cin>>j;
    sort(v.begin(),v.end());
    int j = n-1,xp=0,cnt=0;
    for(int i = 0;i<=j;i++){
        while(xp+v[j].second<v[i].first&&j>=i){
            xp+=v[j].second;
            cnt+=2*v[j].second;
            j--;
        }
        if(j>=i){
            v[j].second-=v[i].first-xp;
            cnt+=(v[i].first-xp)*2+v[i].second;
            xp=v[i].second+v[i].first;
            if(v[j].second==0)j--;
        }
    }cout<<cnt<<endl;
}
/*
cnt=7
xp=4
j i
3 4 5
1 3 1
*/
SubtaskSumTestVerdictTimeMemory
base3/40
1Accepted0/01ms316 KiB
2Wrong answer0/013ms656 KiB
3Wrong answer0/21ms560 KiB
4Wrong answer0/21ms416 KiB
5Wrong answer0/210ms616 KiB
6Wrong answer0/221ms892 KiB
7Wrong answer0/23ms316 KiB
8Wrong answer0/24ms476 KiB
9Accepted3/31ms316 KiB
10Wrong answer0/31ms316 KiB
11Wrong answer0/31ms316 KiB
12Wrong answer0/31ms316 KiB
13Wrong answer0/41ms316 KiB
14Wrong answer0/41ms316 KiB
15Wrong answer0/237ms1192 KiB
16Wrong answer0/250ms1460 KiB
17Wrong answer0/241ms1264 KiB
18Wrong answer0/265ms1776 KiB