-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_subArraySum_Equals_K.cpp
More file actions
66 lines (55 loc) · 1.05 KB
/
A_subArraySum_Equals_K.cpp
File metadata and controls
66 lines (55 loc) · 1.05 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
#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;
ll sum=0,l=0,r=0,f=0;
int arr[n];
fr(0,n){
cin>>arr[i];
}
for(; l<n && r<n; ){
sum+=arr[r];
if(sum==a){
f=1;
break;
}
if(sum<a){
r++;
}
else{
sum-=arr[r];
sum-=arr[l];
l++;
}
}
cout<<l<<" "<<r<<endl;
}
return 0;
}
void init() {
//int i, j, n, m;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
}