Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <queue>
- using namespace std;
- int main(int argc, char** argv) {
- freopen("sample_input.txt", "r", stdin);
- setbuf(stdout, NULL);
- int T;
- int test_case;
- scanf("%d", &T);
- for(test_case = 1; test_case <= T; test_case++) {
- int N, S;
- int sum=0, n=0, smallest=0;
- scanf("%d %d", &N, &S);
- queue<int> num_list;
- for (int i=0;i<N;++i) {
- int num;
- scanf("%d", &num);
- sum+=num; n++;
- num_list.push(num);
- while (sum >= S) {
- if (!smallest || smallest > n) {
- smallest = n;
- }
- int front = num_list.front();
- sum-=front;
- num_list.pop();
- n--;
- }
- }
- printf("#testcase%d\n", test_case);
- printf("%d\n",smallest);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement