fork(2) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define TASK "test"
  6.  
  7. const int INF=1e9;
  8.  
  9. main()
  10. {
  11. freopen(TASK".in","r",stdin);
  12. freopen(TASK".out","w",stdout);
  13. ios::sync_with_stdio(0);
  14. cin.tie(0);
  15. int T;
  16. cin>>T;
  17. while(T--)
  18. {
  19. int n,x;
  20. cin>>n>>x;
  21. vector<int> a(n);
  22. for(int i=0;i<n;i++) cin>>a[i];
  23. deque<pair<int,int>> que;
  24. int ans=INF;
  25. int cur=0;
  26. for(int i=0;i<n;i++)
  27. {
  28. cur+=a[i];
  29. while(!que.empty() && que.back().first>cur) que.pop_back();
  30. que.push_back({cur,i});
  31. while(que.size()>2 && cur-que[1].first>=x) que.pop_front();
  32. if(que.front().second!=i && cur-que.front().first>=x) ans=min(ans,i-que.front().second);
  33. if(a[i]>=x) ans=1;
  34. }
  35. if(ans==INF) cout<<-1<<endl;
  36. else cout<<ans<<endl;
  37. }
  38. }
  39.  
  40.  
  41.  
Runtime error #stdin #stdout #stderr 0s 3436KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file