-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW1_C9.cpp
More file actions
67 lines (57 loc) · 857 Bytes
/
W1_C9.cpp
File metadata and controls
67 lines (57 loc) · 857 Bytes
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
#include <iostream>
#include <fstream>
int main()
{
std::ifstream ipfl;
ipfl.open("input.txt");
int n;
ipfl >> n;
float nary[15];
for (int i = 0; i < n; i++)
{
ipfl >> nary[i];
nary[i] /= 60;
}
ipfl.close();
float sum = 0;
float used[15];
float unused[15];
int uc = 0, uuc = 0;
int count = 0;
for (int i = 0; i < n; i++)
{
sum += nary[i];
if (sum <= 300)
{
count++;
used[uc] = nary[i];
uc++;
}
else
{
sum -= nary[i];
unused[uuc] = nary[i];
uuc++;
}
}
int count2 = count;
for (int i = 0; i < uc; i++)
{
sum -= used[i];
count2--;
for (int j = 0; j < uuc; j++)
{
sum += unused[j];
if (sum <= 300)
count2++;
else
sum -= unused[j];
}
}
count = count > count2 ? count : count2;
std::ofstream opfl;
opfl.open("output.txt");
opfl << count;
opfl.close();
return 0;
}