-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayfit.cpp
68 lines (58 loc) · 1.11 KB
/
playfit.cpp
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>
const long N = 100000L;
const long G = 1000000L;
long gdiff[N];
long goals[N];
void findMaxDiff(long nn)
{
gdiff[0] = 0;
long min_goal = goals[0];
for(long n=1;n<nn;++n)
{
if(goals[n] < gdiff[n-1])
{
gdiff[n] = gdiff[n-1];
if(goals[n] < min_goal)
{
min_goal = goals[n];
}
continue;
}
if(goals[n] - min_goal > gdiff[n-1])
{
gdiff[n] = goals[n] - min_goal;
}
else
{
gdiff[n] = gdiff[n-1];
}
if(goals[n] < min_goal)
{
min_goal = goals[n];
}
}
}
int main(void)
{
int tc;
std::cin >> tc;
for(int c=0; c<tc; ++c)
{
long nn;
std::cin >> nn;
for(long n=0; n<nn ;++n)
{
std::cin >> goals[n];
}
findMaxDiff(nn);
if(gdiff[nn-1] > 0)
{
std::cout << gdiff[nn-1] << std::endl;
}
else
{
std::cout << "UNFIT" << std::endl;
}
}
return 0;
}