git reimport
This commit is contained in:
52
archive/2018.10/2018.10.29 - SNCK1B19/QUEUE2.java
Normal file
52
archive/2018.10/2018.10.29 - SNCK1B19/QUEUE2.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user