-
Notifications
You must be signed in to change notification settings - Fork 0
/
hack_rank.cpp
57 lines (55 loc) · 1.18 KB
/
hack_rank.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int get_point(vector<int>& arr,int left,int right){
if(left>=right)return 0;
if((right-left+1)%2==1)return 0;
vector<int> nxt(arr.size(),0);
int i = left;
int j = right;
int cnt = right;
int ls = 0;
int rs = 0;
while(cnt>=left){
if(ls < rs){
ls += arr[i];
nxt[i] = arr[cnt];
i++;
}else{
ls += arr[j];
nxt[j] = arr[cnt];
j--;
}
cnt--;
}
if(ls != rs){
return 0;
}else{
return 1+max(get_point(arr,left,i-1),get_point(arr,j+1,right));
}
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
int test;
cin>>test;
cout<<test<<endl;
while(test > 0){
int n;
cin>>n;
vector<int> arr;
for(int i =0;i < n;i++){
int a;
cin>>a;
arr.push_back(a);
cout<<a<<" ";
}
cout<<endl;
int res = get_point(arr,0,n-1);
printf("%d\n",res);
test--;
}
}