Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define newl cout<<"\n";
- #define space cout<<" ";
- #define sz(x) x.size()
- #define NumOfDigit(w) log10(w) + 1
- #define MOD 1'000'000'007
- #define inf 2'000'000'000
- #define PI 3.141592654
- #define modulo(a, b, mod) ((((a) % (mod)) + ((b) % (mod))) % (mod))
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define fixed(n) fixed << setprecision(n)
- using namespace std;
- void zainab_hamdy(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- //freopen("collisions.in" , "r" ,stdin);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll gcd(ll a, ll b){
- while(b) {
- a %= b;
- swap(a, b);
- }
- return a;
- }
- int main(){
- zainab_hamdy();
- int t; cin>>t;
- while(t--){
- int n,sum,sum1=0; cin>>n>>sum;
- vector<int> v(n);
- for(int i=0;i<n;i++) {
- cin>>v[i];
- sum1+=v[i];
- }
- if(sum> sum1){
- cout<<"-1\n";
- continue;
- }
- int pre[n+2]{};
- for(int i=1;i<n+1;i++){
- pre[i]=pre[i-1]+v[i-1];
- }
- /*
- for(int i=1;i<n+1;i++){
- cout<< pre[i]<<" ";
- }newl*/
- int idx=0;
- for(int i=0;i<n/2 +1;i++){
- if(pre[n-idx]-pre[idx]== sum){
- // cout<<pre[n-idx] <<" "<< pre[idx] <<" ";
- cout<<idx<<"\n";
- break;
- }
- else idx++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement