Submission #831476

#TimeUsernameProblemLanguageResultExecution timeMemory
831476waldiBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
416 ms40392 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...