题目链接:Codeforces Round 826 (Div. 3) C
- // Problem: C. Minimize the Thickness
- // Contest: Codeforces - Codeforces Round 826 (Div. 3)
- // URL: https://codeforces.com/contest/1741/problem/C
- // Memory Limit: 256 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
-
- #include<bits/stdc++.h>
- using namespace std;
-
- typedef long long ll;
-
- const int N = 2e5+5;
-
- int n;
- int a[N],s[N];
-
- int main(){
- int T;
- cin>>T;
- while(T--){
- cin>>n;
- for(int i=1;i<=n;i++){
- cin>>a[i];
- }
- s[1]=a[1];
- for(int i=2;i<=n;i++){
- s[i]=s[i-1]+a[i];
- }
-
- int res=n;
- for(int i=1;i<=n;i++){
- int ans=i;
- int sum=s[i]; //遍历前几个数
- int k=i;
- for(int j=i+1;j<=n;j++){ //往后遍历
- if(s[j]-s[k]==sum){ //如果后面有等于s[i]的
- ans=max(ans,j-k); //更新长度
- k=j; //k等于当前的j,j继续向后遍历
- }
- }
- if(k==n){ //遍历所以的i,找到最小的长度
- res=min(res,ans);
- }
- }
- cout<<res<<"\n";
-
-
-
- }
-
-
- return 0;
-
- }