-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·54 lines (42 loc) · 907 Bytes
/
Copy pathsol.cpp
File metadata and controls
executable file
·54 lines (42 loc) · 907 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
#include <bits/stdc++.h>
using namespace std;
vector<int> parseInput()
{
int n;
cin >> n;
vector<int> V(n);
for (int i = 0; i < n; ++i)
{
cin >> V[i];
}
return V;
}
vector<int> prefixSum(vector<int> V)
{
for (int i = 1; i < V.size(); ++i)
V[i] += V[i - 1];
return V;
}
int main()
{
vector<int> V = parseInput();
int sum = accumulate(V.begin(), V.end(), 0);
int target;
if (sum % 3 == 0)
target = sum / 3;
else
{
cout << -1 << endl;
return 0;
}
vector<int> prefix_sum = prefixSum(V);
vector<int> indices;
for (int i = 0; i < prefix_sum.size() && indices.size() < 2; ++i)
if (prefix_sum[i] % target == 0)
indices.push_back(i + 1);
if (indices.size() == 2)
cout << indices[0] << " " << indices[1];
else
cout << -1 << endl;
return 0;
}