110332024-06-28 11:01:05BaranJModern Artcpp17Wrong answer 0/10017ms1528 KiB
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n; cin>>n;
    vector<pair<long long, int>> t(2*n);
    vector<int> x(n);
    for(int i=0; i<n; i++){
        cin>>x[i];
    }
    for(int i=0; i<n; i++){
        int r; cin>>r;
        t[2*i]={x[i]-r, 2*r};
        t[2*i+1]={x[i]+r, -2*r};
    }
    sort(t.begin(), t.end());
    long long unio=0, most=0, previ=0;
    map<int, int> m;
    m[0]=1;

    for(int i=0; i<2*n; i++){
        unio+=most*(t[i].first-previ);
        //cout<<most<<" "<<t[i].first<<" "<<previ<<" "<<most*(t[i].first-previ)<<endl;
        previ=t[i].first;
        while(true){
            if(t[i].second > 0){m[-t[i].second]++;}
            else{
                m[t[i].second]--;
                if(m[t[i].second]==0){
                    m.erase(t[i].second);
                }
            }

            if(i >=2*n-1 || t[i].first!=t[i+1].first){break;}
            i++;
        }
        /*for (auto itr = m.begin(); itr != m.end(); ++itr) {
            cout << itr->first
             << '\t' << itr->second << '\n';
        }*/

        most=-m.begin()->first;
        //cout<<most<<" ";
    }
    cout<<endl<<unio;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer2ms356 KiB
2Wrong answer2ms356 KiB
subtask20/5
3Wrong answer6ms872 KiB
4Wrong answer8ms780 KiB
5Wrong answer8ms656 KiB
6Wrong answer10ms892 KiB
7Wrong answer12ms840 KiB
8Wrong answer9ms756 KiB
9Wrong answer9ms740 KiB
10Wrong answer3ms504 KiB
subtask30/15
11Wrong answer3ms508 KiB
12Wrong answer3ms356 KiB
13Wrong answer3ms504 KiB
14Wrong answer3ms384 KiB
15Wrong answer3ms356 KiB
16Wrong answer2ms496 KiB
17Wrong answer3ms516 KiB
18Wrong answer3ms504 KiB
19Wrong answer3ms504 KiB
subtask40/30
20Wrong answer3ms356 KiB
21Wrong answer3ms484 KiB
22Wrong answer3ms356 KiB
23Wrong answer4ms484 KiB
24Wrong answer3ms428 KiB
25Wrong answer3ms356 KiB
26Wrong answer3ms496 KiB
27Wrong answer3ms620 KiB
28Wrong answer3ms356 KiB
subtask50/50
29Wrong answer3ms572 KiB
30Wrong answer4ms356 KiB
31Wrong answer6ms572 KiB
32Wrong answer12ms912 KiB
33Wrong answer12ms760 KiB
34Wrong answer7ms668 KiB
35Wrong answer13ms1016 KiB
36Wrong answer4ms504 KiB
37Wrong answer14ms892 KiB
38Wrong answer14ms868 KiB
39Wrong answer3ms356 KiB
40Wrong answer14ms1188 KiB
41Wrong answer14ms1256 KiB
42Wrong answer14ms1380 KiB
43Wrong answer14ms1320 KiB
44Wrong answer17ms1404 KiB
45Wrong answer17ms1528 KiB