fork download
  1. #include <bits/stdc++.h>
  2. // #include <ext/pb_ds/assoc_container.hpp>
  3. // #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. // using namespace __gnu_pbds;
  6. #define ll long long
  7. #define ld long double
  8. #define ln '\n'
  9. const ll MOD = 1e9 + 7;
  10. // fixed << setprecision()
  11.  
  12. // bool cmp(pair<int, int>& a,
  13. // pair<int , int>& b)
  14. // {
  15. // return a.second < b.second;
  16. // }
  17.  
  18. // template <class T>
  19. // using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  20.  
  21. // template <class type1>
  22. // using ordered_multiset = tree<type1, null_type, less_equal<type1>, rb_tree_tag, tree_order_statistics_node_update>;
  23.  
  24.  
  25. int main()
  26. {
  27. ios_base::sync_with_stdio(false);
  28. cin.tie(NULL);
  29. cout.tie(NULL);
  30.  
  31. // 7 20
  32. // 2 6 4 3 6 8 9
  33.  
  34. int n;
  35. ll s;
  36. cin>>n>>s;
  37. ll count = 0;
  38. ll arr[n];
  39. int l = 0;
  40. ll sum = 0;
  41. for (int i = 0; i < n; i++)
  42. {
  43. cin>>arr[i];
  44. sum += arr[i];
  45. while (sum >= s && l <= i){
  46. count += (n-i);
  47. sum -= arr[l];
  48. l++;
  49. }
  50. }
  51.  
  52. cout<<count<<ln;
  53.  
  54. return 0;
  55. }
  56.  
  57.  
  58.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0