POJ-3061 Subsequence
作者:互联网
Subsequence
找一个最短的区间,使得区间和大于等于s
尺取模板
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;
int num[maxn];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, m;
scanf("%d%d", &n, &m);
for(int i=0; i<n; i++)
scanf("%d", &num[i]);
bool flag = false;
int l = 0, r = 0, sum = 0, ans = n;
while(1)
{
while(r < n && sum < m)
sum += num[r++];
int x = r - l;
if(sum < m) break;
flag = true;
ans = min(ans, x);
sum -= num[l++];
}
if(!flag) ans = 0;
printf("%d\n", ans);
}
return 0;
}
标签:const,int,ll,Subsequence,long,3061,POJ,maxn,include 来源: https://www.cnblogs.com/dgsvygd/p/16265195.html