Created
September 14, 2017 13:19
-
-
Save zhjwpku/c9217142ce3acc390e2c1e2697a5282c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Jiepijiu { | |
public static void main(String [] args) { | |
int w[] = new int[10010]; | |
int lastw[] = new int[10010]; | |
Scanner scanner = new Scanner(System.in); | |
int n = scanner.nextInt(); | |
int m = scanner.nextInt(); | |
int time = 0; | |
for (int i = 1; i <= n; i++) { | |
w[i] = scanner.nextInt(); | |
} | |
for (int i = 1; i < m; i++) { | |
lastw[i] = w[i]; | |
} | |
int i = m + 1; | |
while (i <= n) { | |
int time_min = Integer.MAX_VALUE; | |
for (int j = 1; j <= m; j++) { | |
time_min = Math.min(time_min, lastw[j]); | |
} | |
time += time_min; | |
for (int j = 1; j <= m; j++) { | |
lastw[j] -= time_min; | |
if (lastw[j] == 0) { | |
lastw[j] = w[i]; | |
i++; | |
} | |
} | |
} | |
int time_min = 0; | |
for (int k = 1; k <= m; k++) { | |
time_min = Math.max(time_min, lastw[k]); | |
} | |
time += time_min; | |
System.out.println(time); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment