fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void solve() {
  6. int n;
  7. ll l, r;
  8. cin >> n >> l >> r;
  9.  
  10. vector<ll> a(n);
  11. for (int i = 0; i < n; i++) cin >> a[i];
  12.  
  13. ll current_sum = 0, ans = 0;
  14.  
  15. for (int i = 0; i < n; i++) {
  16. if (a[i] > r) {
  17. // Single card is too large, reset sum
  18. current_sum = 0;
  19. } else if (a[i] >= l && a[i] <= r) {
  20. // Single card itself forms a valid round
  21. ans++;
  22. current_sum = 0;
  23. } else {
  24. // Accumulate sum
  25. current_sum += a[i];
  26. if (current_sum >= l && current_sum <= r) {
  27. ans++;
  28. current_sum = 0; // Reset for the next round
  29. } else if (current_sum > r) {
  30. current_sum = 0; // Reset if sum exceeds r
  31. }
  32. }
  33. }
  34.  
  35. cout << ans << endl;
  36. }
  37.  
  38. int main() {
  39. ios::sync_with_stdio(0);
  40. cin.tie(0);
  41.  
  42. int t;
  43. cin >> t;
  44. while (t--) {
  45. solve();
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5276KB
stdin
8
5 3 10
2 1 11 3 7
10 1 5
17 8 12 11 7 11 21 13 10 8
3 4 5
3 4 2
8 12 25
10 7 5 13 8 9 12 7
2 3 3
5 2
9 7 9
2 10 5 1 3 7 6 2 3
1 8 10
9
5 5 6
1 4 2 6 4
stdout
3
0
1
4
0
3
1
2