-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_subArraySum_Equals_k.cpp
More file actions
72 lines (61 loc) · 1.18 KB
/
2_subArraySum_Equals_k.cpp
File metadata and controls
72 lines (61 loc) · 1.18 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define fr(a, b) for(ll i = a; i < b; i++)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
void init();
int main(){
init();
int t;
cin>>t;
while(t--){
int n,a;
cin>>n>>a;
vi v;
ll sum=0,l=0,r=0,f=0,cnt=0;
int arr[n];
fr(0,n){
cin>>arr[i];
}
for(; l<n && r<n; ){
sum+=arr[r];
if(sum==a){
v.pb(l);
v.pb(r);
cnt++;
if(cnt==2) break;
}
if(sum<a){
r++;
}
else{
sum-=arr[r];
sum-=arr[l];
l++;
}
}
for(int i=0; i<v.size(); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
return 0;
}
void init() {
//int i, j, n, m;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
}