104522024-04-02 20:43:41111Modern Artcpp17Accepted 100/1009ms6524 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1976 KiB
2Accepted3ms2180 KiB
subtask25/5
3Accepted4ms2552 KiB
4Accepted4ms2820 KiB
5Accepted7ms3528 KiB
6Accepted8ms4244 KiB
7Accepted9ms4588 KiB
8Accepted8ms4420 KiB
9Accepted8ms4172 KiB
10Accepted3ms3116 KiB
subtask315/15
11Accepted3ms3100 KiB
12Accepted3ms3200 KiB
13Accepted3ms3320 KiB
14Accepted3ms3332 KiB
15Accepted3ms3460 KiB
16Accepted3ms3544 KiB
17Accepted3ms3748 KiB
18Accepted3ms3964 KiB
19Accepted3ms4184 KiB
subtask430/30
20Accepted3ms4240 KiB
21Accepted3ms4528 KiB
22Accepted3ms4668 KiB
23Accepted3ms4816 KiB
24Accepted3ms4796 KiB
25Accepted3ms4696 KiB
26Accepted3ms4676 KiB
27Accepted3ms4932 KiB
28Accepted3ms4780 KiB
subtask550/50
29Accepted3ms4720 KiB
30Accepted3ms4908 KiB
31Accepted4ms5144 KiB
32Accepted4ms5108 KiB
33Accepted4ms5072 KiB
34Accepted4ms5020 KiB
35Accepted7ms5488 KiB
36Accepted4ms5160 KiB
37Accepted7ms5224 KiB
38Accepted7ms5164 KiB
39Accepted3ms4984 KiB
40Accepted9ms6368 KiB
41Accepted9ms6384 KiB
42Accepted9ms6380 KiB
43Accepted9ms6380 KiB
44Accepted8ms6384 KiB
45Accepted8ms6524 KiB