This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ll unsigned long long
using namespace __gnu_pbds;
#define modu 1000000007
typedef tree<long,null_type,less<long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//hyper_adj[a] -> b then (a before b)
#define sizeofA 200002
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
long N;
long A[sizeofA] = {};
long xuoi1[sizeofA] = {};
long xuoi2[sizeofA] = {};
long carry1[sizeofA] = {};
long carry2[sizeofA] = {};
long val1[sizeofA]= {};
long val2[sizeofA]= {};
long lefter = 0;
long walter = 0;
cin>>N;
ll ans = 2000000000000000000;
for (long i = 1;i<=N;i++){
cin>>A[i];
xuoi1[i] = xuoi1[i-1] + max((long)0,A[i-1]+1-A[i]);
}
lefter = 0;
for (long i = N;i>=1;i--){
xuoi2[i] = xuoi2[i+1] +max((long)0,A[i+1]+1-A[i]);
}
for (long i = 1;i<=N;i++){
ans = min(ans, (ll)(xuoi1[i]+xuoi2[i] - min(xuoi1[i],xuoi2[i])));
}
cout<<ans;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:28:10: warning: unused variable 'carry1' [-Wunused-variable]
28 | long carry1[sizeofA] = {};
| ^~~~~~
Main.cpp:29:10: warning: unused variable 'carry2' [-Wunused-variable]
29 | long carry2[sizeofA] = {};
| ^~~~~~
Main.cpp:30:10: warning: unused variable 'val1' [-Wunused-variable]
30 | long val1[sizeofA]= {};
| ^~~~
Main.cpp:31:10: warning: unused variable 'val2' [-Wunused-variable]
31 | long val2[sizeofA]= {};
| ^~~~
Main.cpp:32:10: warning: variable 'lefter' set but not used [-Wunused-but-set-variable]
32 | long lefter = 0;
| ^~~~~~
Main.cpp:33:10: warning: unused variable 'walter' [-Wunused-variable]
33 | long walter = 0;
| ^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |