155882025-02-20 19:15:21999Bányász RPG (40 pont)cpp17Wrong answer 26/4067ms1588 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-=max(v[i].first-xp,0LL);
            cnt+=max(0LL,(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=0
xp=0
i   j
0 0 0
1 2 3
*/
SubtaskSumTestVerdictTimeMemory
base26/40
1Accepted0/01ms316 KiB
2Wrong answer0/013ms564 KiB
3Accepted2/21ms548 KiB
4Accepted2/22ms608 KiB
5Accepted2/29ms608 KiB
6Accepted2/221ms892 KiB
7Accepted2/23ms508 KiB
8Accepted2/24ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Wrong answer0/31ms316 KiB
12Wrong answer0/31ms316 KiB
13Wrong answer0/41ms316 KiB
14Accepted4/41ms316 KiB
15Wrong answer0/239ms1192 KiB
16Accepted2/250ms1460 KiB
17Wrong answer0/241ms1272 KiB
18Accepted2/267ms1588 KiB