git reimport

This commit is contained in:
2019-03-15 13:47:54 +04:00
commit 3b461f73de
489 changed files with 1631603 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package chelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class QUEUE2 extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
long n = in.nextLong();
long m = in.nextLong() + 1;
long k = in.nextLong();
long l = in.nextLong();
long lastFree = 0;
List<Long> a = new ArrayList<>();
for (long i = 0; i < n; i++) {
a.add(in.nextLong());
}
Collections.sort(a);
a.add(k);
long minWaitTime = m * l;
for (long i : a) {
long newlyFree = (i - lastFree) / l;
lastFree += newlyFree * l;
m = Math.max(0, m - newlyFree);
if (m == 0) {
lastFree = i;
}
minWaitTime = Math.min(minWaitTime, Math.max(lastFree + m * l - i, 0));
m++;
}
out.println(minWaitTime);
}
}