10452 | 2024-04-02 20:43:41 | 111 | Modern Art | cpp17 | Accepted 100/100 | 9ms | 6524 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<pair<int,int>>v(N);
for(int i=0;i<N;i++){
cin>>v[i].second;
}
for(int i=0;i<N;i++){
cin>>v[i].first;
}
sort(v.rbegin(),v.rend());
int ans=0;
map<int,int>c;
for(auto[r,x]:v){
int s=x-r,e=x+r;
auto t=c.lower_bound(x);
if(t!=c.end()){
e=min(e,t->first-t->second);
}
if(t!=c.begin()){
s=max(s,prev(t)->first+prev(t)->second);
}
if(e>s){
ans+=(e-s)*r*2;
if(!c.count(x)){
c[x]=r;
}
}
}
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1976 KiB | ||||
2 | Accepted | 3ms | 2180 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 4ms | 2552 KiB | ||||
4 | Accepted | 4ms | 2820 KiB | ||||
5 | Accepted | 7ms | 3528 KiB | ||||
6 | Accepted | 8ms | 4244 KiB | ||||
7 | Accepted | 9ms | 4588 KiB | ||||
8 | Accepted | 8ms | 4420 KiB | ||||
9 | Accepted | 8ms | 4172 KiB | ||||
10 | Accepted | 3ms | 3116 KiB | ||||
subtask3 | 15/15 | ||||||
11 | Accepted | 3ms | 3100 KiB | ||||
12 | Accepted | 3ms | 3200 KiB | ||||
13 | Accepted | 3ms | 3320 KiB | ||||
14 | Accepted | 3ms | 3332 KiB | ||||
15 | Accepted | 3ms | 3460 KiB | ||||
16 | Accepted | 3ms | 3544 KiB | ||||
17 | Accepted | 3ms | 3748 KiB | ||||
18 | Accepted | 3ms | 3964 KiB | ||||
19 | Accepted | 3ms | 4184 KiB | ||||
subtask4 | 30/30 | ||||||
20 | Accepted | 3ms | 4240 KiB | ||||
21 | Accepted | 3ms | 4528 KiB | ||||
22 | Accepted | 3ms | 4668 KiB | ||||
23 | Accepted | 3ms | 4816 KiB | ||||
24 | Accepted | 3ms | 4796 KiB | ||||
25 | Accepted | 3ms | 4696 KiB | ||||
26 | Accepted | 3ms | 4676 KiB | ||||
27 | Accepted | 3ms | 4932 KiB | ||||
28 | Accepted | 3ms | 4780 KiB | ||||
subtask5 | 50/50 | ||||||
29 | Accepted | 3ms | 4720 KiB | ||||
30 | Accepted | 3ms | 4908 KiB | ||||
31 | Accepted | 4ms | 5144 KiB | ||||
32 | Accepted | 4ms | 5108 KiB | ||||
33 | Accepted | 4ms | 5072 KiB | ||||
34 | Accepted | 4ms | 5020 KiB | ||||
35 | Accepted | 7ms | 5488 KiB | ||||
36 | Accepted | 4ms | 5160 KiB | ||||
37 | Accepted | 7ms | 5224 KiB | ||||
38 | Accepted | 7ms | 5164 KiB | ||||
39 | Accepted | 3ms | 4984 KiB | ||||
40 | Accepted | 9ms | 6368 KiB | ||||
41 | Accepted | 9ms | 6384 KiB | ||||
42 | Accepted | 9ms | 6380 KiB | ||||
43 | Accepted | 9ms | 6380 KiB | ||||
44 | Accepted | 8ms | 6384 KiB | ||||
45 | Accepted | 8ms | 6524 KiB |