fork(8) download
  1. #include <vector>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <queue>
  5. #include <cctype>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <iostream>
  9. #include <bitset>
  10. #include <map>
  11. #include <complex>
  12. #include <ctime>
  13. #include <numeric>
  14. #include <set>
  15. #include <cassert>
  16.  
  17. using namespace std;
  18.  
  19. typedef long long ll;
  20. typedef pair<ll, int> pi;
  21.  
  22.  
  23. #define N 500005
  24.  
  25. ll ACC[N];
  26.  
  27. int main()
  28. {
  29. #ifndef ONLINE_JUDGE
  30. freopen("in.in", "r", stdin);
  31. #endif
  32.  
  33. int t, n, X, a;
  34. scanf("%d", &t);
  35. while(t--){
  36. scanf("%d %d", &n, &X);
  37. int besti = 1e9;
  38. for(int i = 1; i <= n; i++){
  39. scanf("%d", &a);
  40. ACC[i] = ACC[i-1] + a;
  41. }
  42. priority_queue< pi, vector<pi>, greater<pi> > pq;
  43. pq.push(pi(ACC[0], 0));
  44. for(int i = 1; i <= n; i++){
  45. while(!pq.empty() && ACC[i] - pq.top().first >= X ){
  46. besti = min(besti, i - pq.top().second);
  47. pq.pop();
  48. }
  49. pq.push(pi(ACC[i], i));
  50. }
  51. printf("%d\n", besti > n ? -1 : besti);
  52. }
  53.  
  54.  
  55.  
  56. return 0;
  57. }
  58.  
Runtime error #stdin #stdout 0.17s 7248KB
stdin
Standard input is empty
stdout
Standard output is empty