Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define INF 1<<30
  4. #define MAX 10005
  5. #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  6. typedef long long ll;
  7.  
  8.  
  9. int main()
  10. {
  11. //FASTIO
  12. /*
  13. //double start_time = clock();
  14. #ifndef ONLINE_JUDGE
  15. freopen("in.txt", "r", stdin);
  16. freopen("out.txt", "w", stdout);
  17. freopen("error.txt", "w", stderr);
  18. #endif
  19. //*/
  20.  
  21. int n,s;
  22. while(cin >> n >> s){
  23. int a[n+2];
  24. for(int i = 0; i < n; i++){
  25. cin >> a[i];
  26. }
  27. int length = 999999;
  28. int low = 0, high = 0;
  29. int sum = a[0];
  30. while(high < n){
  31. if(sum >= s){
  32. int cnt = high - low + 1;
  33. length = min(length, cnt);
  34. }
  35. if(sum >= s && low < high){
  36. sum -= a[low];
  37. low++;
  38. }
  39. else if(sum < s){
  40. high++;
  41. if(high < n)
  42. sum += a[high];
  43. }
  44. }
  45. if(length == 999999) length = 0;
  46. cout << length << "\n";
  47. }
  48.  
  49. //double end_time = clock();
  50. //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement