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<bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
typedef long long ll;
using namespace std;
ll delivery(int n, int k, int l, int poz[]){
ll wyn = ((ll)n)*((ll)l);
FOR(off, 1, min(n, k)){
ll twyn = 0ll;
for(int i = off-1; 1; i += k){
int poc = poz[max(i-k+1, 0)];
int kon = poz[min(i, n-1)];
if(kon <= l>>1) twyn += kon<<1;
else if(poc >= (l+1)>>1) twyn += (l-poc)<<1;
else twyn += l;
if(i >= n-1) break;
}
wyn = min(wyn, twyn);
}
return wyn;
}
#ifdef LOCAL
#define maxn 1000
int main(){
int n, k, l, p[maxn];
scanf("%d%d%d", &n, &k, &l);
REP(i, n) scanf("%d", &p[i]);
ll wyn = delivery(n, k, l, p);
printf("%lld\n", wyn);
}
#endif
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |