Guest User

Untitled

a guest
Jun 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. //author @ Ayush Aggarwal
  2. // Let's Do this shit.
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. typedef long long ll;
  6.  
  7. int main()
  8. {  
  9.     ios::sync_with_stdio(false);
  10.     cin.tie(NULL);
  11.     ll t;
  12.     cin>>t;
  13.     while(t--) 
  14.     {
  15.         map <ll,ll> mp;
  16.         mp.clear();
  17.         mp[0]++;
  18.         ll sum=0,n,k,ans=0;
  19.         cin>>n>>k;
  20.         ll a[n];
  21.         string str;
  22.         cin>>str;
  23.         for(ll i=0;i<n;i++)
  24.         {
  25.             a[i] = str[i] - (ll)'a' + 49;
  26.             //cout<<a[i]<<endl;
  27.             sum +=a[i];
  28.             //cout<<sum<<endl;
  29.             ans +=mp[sum-k];
  30.             //cout<<ans<<endl;
  31.             mp[sum]++;
  32.         //  cout<<mp[sum]<<endl;
  33.         }
  34.         cout<<ans<<endl;
  35.     }
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment