-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarn Repair.c
More file actions
79 lines (79 loc) · 1.27 KB
/
Barn Repair.c
File metadata and controls
79 lines (79 loc) · 1.27 KB
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
79
/*
ID: sunheco1
LANG: C
TASK: barn1
*/
#include<stdio.h>
int map[222],mm[222],m,s,c,now;
int next(int i)
{
while(map[i]==0)
i++;
return i;
}
int find(int i)
{
int j=i;
while(map[i]==0)
i++;
return i-j;
}
int min()
{
int i,j,min=2222;
for(i=1;i<=now;i++)
{
if(mm[i]<min)
{
j=i;
min=mm[j];
}
}
i=mm[j];
mm[j]=2222;
return i;
}
int main()
{
int i,tar,tem=0;
FILE *fin = fopen ("barn1.in", "r");
FILE *fout = fopen ("barn1.out", "w");
fscanf(fin,"%d %d %d",&m,&s,&c);
for(i=1;i<=c;i++)
{
fscanf(fin,"%d",&tar);
map[tar]=1;
}
while(map[s]==0)
s--;
now=1;
i=1;
while(map[i]==0)
i++;
while(i<=s)
{
if(map[i])
{
while(map[i])
i++;
}
else
{
tar=find(i);
i=next(i);
mm[now]=tar;
now++;
continue;
}
tem++;
}
now--;
tar=c;
while(tem>m)
{
tar+=min();
tem--;
}
fprintf(fout,"%d\n",tar);
return 0;
}