#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;
typedef pair<int,int> pii;
pii operator+(pii a,pii b){
return {a.fs+b.fs,a.sc+b.sc};
}
pii operator-(pii a,pii b){
return {a.fs-b.fs,a.sc-b.sc};
}
int dot(pii a,pii b){
return a.fs*b.fs+a.sc*b.sc;
}
int cross(pii a,pii b){
return a.fs*b.sc-b.fs*a.sc;
}
int sign(int x){
if(x==0){
return 0;
}
if(x>0){
return 1;
}
else{
return -1;
}
}
int ori(pii a,pii b,pii c){
return sign(cross(b-a,c-a));
}
long double slope(pii a,pii b){
return (b.sc-a.sc)*1.0/(1.0*(b.fs-a.fs));
}
signed main(){
AquA;
int n,m;
cin >> n >> m;
vector<int> a(n),b(m);
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int j=0;j<m;j++){
cin >> b[j];
}
vector<pii> c,d;
for(int i=0;i<n;i++){
while(c.size()>=2 && ori(c[c.size()-2],c[c.size()-1],{i,a[i]})<=0){
c.pop_back();
}
c.push_back({i,a[i]});
}
for(int i=0;i<m;i++){
while(d.size()>=2 && ori(d[d.size()-2],d[d.size()-1],{i,b[i]})<=0){
d.pop_back();
}
d.push_back({i,b[i]});
}
int ans=0;
int e=c.size(),f=d.size();
for(int h=0,w=0;h<e-1 || w<f-1;){
if(w!=f-1 && (h==e-1 || slope(c[h],c[h+1])>slope(d[w],d[w+1]))){
ans+=c[h].sc*(d[w+1].fs-d[w].fs);
w++;
}
else{
ans+=d[w].sc*(c[h+1].fs-c[h].fs);
h++;
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
356 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
316 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
476 KB |
Output is correct |
4 |
Correct |
7 ms |
1304 KB |
Output is correct |
5 |
Correct |
9 ms |
1204 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
17 ms |
2636 KB |
Output is correct |
8 |
Correct |
21 ms |
2776 KB |
Output is correct |
9 |
Correct |
18 ms |
2684 KB |
Output is correct |
10 |
Correct |
16 ms |
2644 KB |
Output is correct |
11 |
Correct |
21 ms |
2516 KB |
Output is correct |
12 |
Correct |
20 ms |
2644 KB |
Output is correct |
13 |
Correct |
23 ms |
2648 KB |
Output is correct |
14 |
Correct |
16 ms |
2648 KB |
Output is correct |
15 |
Correct |
26 ms |
2780 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
356 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
316 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
476 KB |
Output is correct |
32 |
Correct |
7 ms |
1304 KB |
Output is correct |
33 |
Correct |
9 ms |
1204 KB |
Output is correct |
34 |
Correct |
4 ms |
596 KB |
Output is correct |
35 |
Correct |
17 ms |
2636 KB |
Output is correct |
36 |
Correct |
21 ms |
2776 KB |
Output is correct |
37 |
Correct |
18 ms |
2684 KB |
Output is correct |
38 |
Correct |
16 ms |
2644 KB |
Output is correct |
39 |
Correct |
21 ms |
2516 KB |
Output is correct |
40 |
Correct |
20 ms |
2644 KB |
Output is correct |
41 |
Correct |
23 ms |
2648 KB |
Output is correct |
42 |
Correct |
16 ms |
2648 KB |
Output is correct |
43 |
Correct |
26 ms |
2780 KB |
Output is correct |
44 |
Correct |
1 ms |
316 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
320 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
12 ms |
1908 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
4 ms |
724 KB |
Output is correct |
59 |
Correct |
24 ms |
3800 KB |
Output is correct |
60 |
Correct |
23 ms |
3792 KB |
Output is correct |
61 |
Correct |
24 ms |
3796 KB |
Output is correct |
62 |
Correct |
24 ms |
3788 KB |
Output is correct |
63 |
Correct |
24 ms |
5832 KB |
Output is correct |
64 |
Correct |
26 ms |
3800 KB |
Output is correct |
65 |
Correct |
25 ms |
3804 KB |
Output is correct |
66 |
Correct |
23 ms |
3808 KB |
Output is correct |
67 |
Correct |
29 ms |
3916 KB |
Output is correct |