Skip to content

Commit eb58de3

Browse files
committed
added
1 parent da03bfc commit eb58de3

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define ll long long
6+
#define pb push_back
7+
#define ppb pop_back
8+
#define F first
9+
#define S second
10+
#define fr(a, b) for(ll i = a; i < b; i++)
11+
typedef pair<int, int> pii;
12+
typedef pair<ll, ll> pl;
13+
typedef vector<int> vi;
14+
typedef vector<ll> vl;
15+
typedef vector<pii> vpii;
16+
typedef vector<pl> vpl;
17+
typedef vector<vi> vvi;
18+
typedef vector<vl> vvl;
19+
20+
void init();
21+
22+
int main(){
23+
init();
24+
int t;
25+
cin>>t;
26+
while(t--){
27+
int n,a;
28+
cin>>n>>a;
29+
vi v;
30+
ll sum=0,l=0,r=0,f=0,cnt=0;
31+
int arr[n];
32+
fr(0,n){
33+
cin>>arr[i];
34+
}
35+
36+
for(; l<n && r<n; ){
37+
sum+=arr[r];
38+
if(sum==a){
39+
v.pb(l);
40+
v.pb(r);
41+
cnt++;
42+
if(cnt==2) break;
43+
}
44+
if(sum<a){
45+
r++;
46+
}
47+
else{
48+
sum-=arr[r];
49+
sum-=arr[l];
50+
l++;
51+
}
52+
}
53+
54+
for(int i=0; i<v.size(); i++){
55+
cout<<v[i]<<" ";
56+
}
57+
cout<<endl;
58+
}
59+
60+
61+
62+
return 0;
63+
}
64+
65+
66+
void init() {
67+
//int i, j, n, m;
68+
#ifndef ONLINE_JUDGE
69+
freopen("input.txt", "r", stdin);
70+
// freopen("output.txt", "w", stdout);
71+
#endif
72+
}

0 commit comments

Comments
 (0)