162482025-04-15 20:22:38RRoliModern Artcpp17Wrong answer 5/10010ms1284 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
    cin >> n;
    vector<pair<pair<unsigned long long,unsigned long long>,unsigned long long>> v(n), sor;
    vector<unsigned long long> pos(n), size(n);
    for(int i = 0; i < n; i++) cin >> pos[i];
    for(int i = 0; i < n; i++) cin >> size[i];
    for(int i = 0; i < n; i++) v[i] = make_pair(make_pair(pos[i]-size[i], pos[i]+size[i]), size[i]*2);
    sort(v.begin(), v.end());

    //for(auto i : v) cout << i.first.first << ' ' << i.first.second << ' ' << i.second << '\n';
    sor.push_back(v[0]);
    for(int i = 1; i < n; i++) {
        if(v[i].first.second > sor[sor.size()-1].first.second) {
            if(v[i].first.first == sor[sor.size()-1].first.first && v[i].second > sor[sor.size()-1].second) {
                sor[sor.size()-1] = v[i];
            } else if(v[i].first.first >= sor[sor.size()-1].first.second) {
                sor.push_back(v[i]);
            } else if(v[i].second >= sor[sor.size()-1].second) {
                sor[sor.size()-1].first.second = v[i].first.first;
                sor.push_back(v[i]);
            } else if(v[i].second < sor[sor.size()-1].second) {
                sor.push_back(v[i]);
                sor[sor.size()-1].first.first = sor[sor.size()-2].first.second;
            }
        }
    }

    unsigned long long s = 0;
    for(auto i : sor) s += (i.first.second-i.first.first)*i.second;
    //cout << i.first.first << ' ' << i.first.second << ' ' << i.second << '\n';
    
    cout << s;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms508 KiB
subtask25/5
3Accepted4ms564 KiB
4Accepted4ms708 KiB
5Accepted6ms972 KiB
6Accepted8ms1076 KiB
7Accepted8ms1272 KiB
8Accepted8ms976 KiB
9Accepted7ms960 KiB
10Accepted1ms508 KiB
subtask30/15
11Accepted1ms316 KiB
12Accepted1ms552 KiB
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer1ms316 KiB
16Wrong answer1ms320 KiB
17Wrong answer1ms604 KiB
18Wrong answer1ms316 KiB
19Wrong answer1ms316 KiB
subtask40/30
20Wrong answer1ms512 KiB
21Accepted1ms508 KiB
22Accepted1ms316 KiB
23Wrong answer2ms316 KiB
24Accepted1ms392 KiB
25Wrong answer1ms508 KiB
26Accepted1ms316 KiB
27Wrong answer1ms316 KiB
28Wrong answer2ms316 KiB
subtask50/50
29Accepted1ms316 KiB
30Wrong answer2ms316 KiB
31Wrong answer3ms360 KiB
32Wrong answer6ms656 KiB
33Wrong answer6ms564 KiB
34Wrong answer3ms316 KiB
35Wrong answer8ms820 KiB
36Wrong answer3ms508 KiB
37Wrong answer9ms768 KiB
38Wrong answer9ms756 KiB
39Wrong answer1ms316 KiB
40Wrong answer9ms1256 KiB
41Accepted8ms1284 KiB
42Wrong answer9ms1256 KiB
43Wrong answer9ms1256 KiB
44Accepted10ms1252 KiB
45Accepted10ms1268 KiB