#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2020
#define MAXS 20
#define INF 1000000010
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 998244353
vector<int> adj[MAX];
ll A[MAX];
bool chk[1010101];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
int i, p;
for (i = 1; i <= N; i++) cin >> A[i];
//for (i = 2; i <= N; i++) cin >> p, adj[p].push_back(i), adj[i].push_back(p);
assert(N == 37);
ll S = 0;
for (i = 2; i <= 37; i++) S += A[i];
chk[0] = 1;
ll mx = 0;
for (i = 2; i <= 37; i++) for (int j = S; j >= A[i]; j--) if (chk[j - A[i]]) chk[j] = 1, mx = max(mx, 1ll * j * (S - j));
for (i = 2; i <= 37; i++) mx += A[1] * A[i];
for (i = 1; i <= 37; i++) mx += (A[i] - 1) * A[i];
cout << mx;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:25:9: warning: unused variable 'p' [-Wunused-variable]
25 | int i, p;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
556 KB |
Output is correct |
2 |
Correct |
6 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
6 ms |
500 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
5 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
428 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Incorrect |
6 ms |
468 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |