Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int main(int argc, char** argv) {
  7.  
  8. freopen("sample_input.txt", "r", stdin);
  9.  
  10. setbuf(stdout, NULL);
  11.  
  12. int T;
  13. int test_case;
  14.  
  15. scanf("%d", &T);
  16. for(test_case = 1; test_case <= T; test_case++) {
  17.  
  18. int N, S;
  19. int sum=0, n=0, smallest=0;
  20. scanf("%d %d", &N, &S);
  21. queue<int> num_list;
  22.  
  23. for (int i=0;i<N;++i) {
  24. int num;
  25. scanf("%d", &num);
  26. sum+=num; n++;
  27.  
  28. num_list.push(num);
  29.  
  30. while (sum >= S) {
  31. if (!smallest || smallest > n) {
  32. smallest = n;
  33. }
  34.  
  35. int front = num_list.front();
  36. sum-=front;
  37. num_list.pop();
  38. n--;
  39.  
  40. }
  41. }
  42.  
  43. printf("#testcase%d\n", test_case);
  44. printf("%d\n",smallest);
  45.  
  46. }
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement