-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20055-1.c
78 lines (64 loc) · 820 Bytes
/
20055-1.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#define NMAX 100
typedef struct
{
int A, R;
} Belt;
Belt belt[2*NMAX] = {0};
Belt temp;
int N, K;
int kcount;
void land()
{
belt[N-1].R = 0;
}
void on()
{
if(belt[0].A)
{
belt[0].R = 1;
belt[0].A--;
if(!belt[0].A)
kcount++;
}
}
void rotate()
{
int i;
temp = belt[2*N-1];
for(i=2*N-1; i>=1; i--)
belt[i] = belt[i-1];
belt[0] = temp;
land();
}
void goRobot()
{
int i;
for(i=N-2; i>=1; i--)
if(belt[i].R && !belt[i+1].R && belt[i+1].A)
{
belt[i].R = 0;
belt[i+1].R = 1;
belt[i+1].A--;
if(!belt[i+1].A)
kcount++;
}
land();
}
int main(void)
{
int i;
int count = 0;
scanf("%d %d", &N, &K);
for(i=0; i<2*N; i++)
scanf("%d", &belt[i].A);
while(kcount < K)
{
rotate();
goRobot();
on();
count++;
}
printf("%d", count);
return 0;
}