-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubarray_sum.cpp
More file actions
50 lines (42 loc) · 959 Bytes
/
subarray_sum.cpp
File metadata and controls
50 lines (42 loc) · 959 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
long long k;
cin>>n>>k;
int a[n];
int last=0;
int start=0;
unsigned long long c_sum=0;
bool f=false;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
{
c_sum += a[i];
if(c_sum>=k)
{
last=i;
while(k<c_sum && start<last)
{
c_sum -= a[start];
++start;
}
if(c_sum==k)
{
cout<<start+1<<" "<<last+1<<endl;
f = true;
break;
}
}
}
if(f==false)
cout<<-1<<endl;
}
return 0;
}