This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long lint;
struct pole{lint a,i;}d[100005];
int cmp(pole a, pole b){return a.a * b.i < b.a * a.i;}
lint n;
lint trial(int piv){
lint res = 0;
for (int i=0; i<n; i++) {
res += max(d[i].a - piv * d[i].i, piv * d[i].i - d[i].a);
}
return res;
}
int main(){
scanf("%lld",&n);
for (int i=0; i<n; i++) {
scanf("%lld",&d[i].a);
d[i].i = i;
}
int s = 0, e = 1e9;
while (s != e) {
int m = (s+e)>>1;
if(trial(m) > trial(m+1)) s = m+1;
else e = m;
}
printf("%lld",trial(s));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |