-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathUVa00144_StudentGrants.java
58 lines (49 loc) · 1.26 KB
/
UVa00144_StudentGrants.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 80 (144 - Student Grants) */
/* SUBMISSION: 11336881 */
/* SUBMISSION TIME: 2013-02-24 16:28:50 */
/* LANGUAGE: 2 */
import java.io.*;
import java.util.*;
public class UVa00144_StudentGrants {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String[] parts = in.readLine().split("[ ]+");
int N = Integer.parseInt(parts[0]);
int k = Integer.parseInt(parts[1]);
if (N == 0 && k == 0)
break;
int[] pay = new int[N];
Queue<Integer> Q = new LinkedList<Integer>();
for (int i = 0; i < N; ++i)
Q.offer(i);
int am = 1;
int store = 0;
while (!Q.isEmpty()) {
//System.out.println("store: " + store + ", amount: " + am);
int x = Q.poll();
if (store == 0) {
store = am;
++am;
if (am > k) am = 1;
}
if (pay[x] + store <= 40) {
pay[x] += store;
store = 0;
} else {
store -= 40 - pay[x];
pay[x] = 40;
}
if (pay[x] < 40)
Q.offer(x);
else
System.out.format("%3d", x + 1);
}
System.out.println();
}
in.close();
System.exit(0);
}
}