-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandos.cpp
More file actions
55 lines (47 loc) · 951 Bytes
/
commandos.cpp
File metadata and controls
55 lines (47 loc) · 951 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
/**
* Asia-Pacific Informatics Olympiad 2010, Q1
* Ananya Kumar, 2011
* NUS High School
*
* Gets 70/100 (Bronze cutoff was 83/300)
*/
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long sfq[1000001] = {0};
long memo[1000001] = {0};
long a, b, c;
long num, sum, prevTemp;
long computePolynomial ( int N )
{
return a * N * N + b * N + c;
}
int main ()
{
long temp;
sum = 0;
int i,j;
cin >> num;
cin >> a >> b >> c;
long polMax = abs((int)(sqrt(abs(c)/(-a))));
cout << c << " " << a << endl;
for ( i = 1; i <= num; i++ )
{
cin >> temp;
sum += temp;
sfq[i] = sum;
}
cout << polMax << " " << (int)(sum/num) << endl;
for ( i = 0; i < num; i++ )
{
for ( j = i+1; j <= num; j++ )
{
temp = computePolynomial(sfq[j] - sfq[i]);
if ( abs(i-polMax) < 110 && i < i < num-1000 ) break;
prevTemp = temp;
memo[j] = max(memo[j],memo[i]+temp);
}
}
cout << memo[num] << endl;
}