fork download
  1. /* AUTHOR: TUAN ANH - BUI */
  2. // ~~ icebear ~~
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. typedef pair<int, int> ii;
  8. typedef pair<int, ii> iii;
  9.  
  10. template<class X, class Y>
  11. bool minimize(X &x, const Y &y) {
  12. if (x > y) return x = y, true;
  13. return false;
  14. }
  15.  
  16. template<class X, class Y>
  17. bool maximize(X &x, const Y &y) {
  18. if (x < y) return x = y, true;
  19. return false;
  20. }
  21.  
  22. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  23. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  24. #define REP(i, n) for(int i=0; i<(n); ++i)
  25. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  26. #define MASK(i) (1LL << (i))
  27. #define BIT(S, i) (((S) >> (i)) & 1)
  28. #define mp make_pair
  29. #define pb push_back
  30. #define fi first
  31. #define se second
  32. #define all(x) x.begin(), x.end()
  33. #define task "icebear"
  34. /*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN TST26 */
  35.  
  36. const int MOD = 1e9 + 7;
  37. const int inf = (int)1e9 + 27092008;
  38. const ll INF = (ll)1e18 + 27092008;
  39. const int N = 2e5 + 5;
  40. int n, k, a[N];
  41. ll pref[N];
  42.  
  43. void init(void) {
  44. cin >> n >> k;
  45. FOR(i, 1, n) cin >> a[i], pref[i] = pref[i - 1] + a[i];
  46. }
  47.  
  48. void process(void) {
  49. ll res = 0;
  50. FOR(i, 1, n) {
  51. int m = upper_bound(pref, pref + n + 1, pref[i] - k) - pref - 1; // tim m thoa pref[m] <= pref[i] - k
  52. res += m + 1;
  53. }
  54. cout << res;
  55. }
  56.  
  57. int main() {
  58. ios_base::sync_with_stdio(0);
  59. cin.tie(0); cout.tie(0);
  60. if (fopen(task".inp", "r")) {
  61. freopen(task".inp", "r", stdin);
  62. freopen(task".out", "w", stdout);
  63. }
  64. int tc = 1;
  65. // cin >> tc;
  66. while(tc--) {
  67. init();
  68. process();
  69. }
  70. return 0;
  71. }
  72.  
  73.  
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty