标签:algo nim namespace second i++ tput mat return each
Input
Output
Sample Input
2 10 15 5 1 3 5 10 7 4 9 2 8 5 11 1 2 3 4 5
Sample Output
2 3
1 #include <iostream> 2 using namespace std; 3 #include<string.h> 4 #include<set> 5 #include<stdio.h> 6 #include<math.h> 7 #include<queue> 8 #include<map> 9 #include<algorithm> 10 #include<cstdio> 11 #include<cmath> 12 #include<cstring> 13 #include <cstdio> 14 #include <cstdlib> 15 #include<stack> 16 #include<vector> 17 long long a[110000]; 18 int main() 19 { 20 long long t; 21 cin>>t; 22 while(t--) 23 { 24 memset(a,0,sizeof(a)); 25 int n,m; 26 cin>>n>>m; 27 long long sum=0; 28 for(int i=1;i<=n;i++) 29 { 30 scanf("%lld",&a[i]); 31 sum+=a[i]; 32 } 33 if(sum<m) 34 { 35 cout<<"0"<<endl; 36 continue; 37 } 38 sum=0; 39 int temp; 40 for(int i=n;i>=1;i--) 41 { 42 sum+=a[i]; 43 if(sum>=m) 44 { 45 temp=i; 46 break; 47 } 48 } 49 int min1; 50 min1=n-temp+1; 51 int kaishi=1,jieshu=0; 52 sum=0; 53 while(1) 54 { 55 56 if(sum<m) 57 { 58 while(sum<m&&jieshu<=n) 59 { 60 sum+=a[++jieshu]; 61 } 62 min1=min(min1,jieshu-kaishi+1); 63 } 64 else 65 { 66 min1=min(min1,jieshu-kaishi+1); 67 sum-=a[kaishi++]; 68 } 69 //cout<<kaishi<<"_"<<jieshu<<"_"<<min1<<endl; 70 if(kaishi==temp) 71 break; 72 } 73 cout<<min1<<endl; 74 } 75 return 0; 76 }
标签:algo nim namespace second i++ tput mat return each
原文地址:http://www.cnblogs.com/dulute/p/7966714.html