-
Notifications
You must be signed in to change notification settings - Fork 0
/
B-B.cpp
40 lines (33 loc) · 929 Bytes
/
B-B.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
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t; cin>>t;
while(t--){
int n;cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)
cin>>a[i];
vector<ll>prefix_sum(n);
vector<ll>suffix_sum(n);
prefix_sum[0]=a[0];
for(int i=1;i<n;i++)
prefix_sum[i]=prefix_sum[i-1]+a[i];
suffix_sum[n-1]=a[n-1];
for(int i=n-2;i>=0;i--)
suffix_sum[i]=suffix_sum[i+1]+a[i];
ll minsum =prefix_sum[0]+suffix_sum[0];
// cout<<minsum<<"minsum"<<endl;
int index=0;
for(int i=1;i<n;i++){
if(prefix_sum[i]+suffix_sum[i]<minsum){
minsum=prefix_sum[i]+suffix_sum[i];
index=i;
}
}
cout<<index+1<<endl;
}
}