#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a[50010],b[50010];
int main(){
int i,j,k,m,n;
int sum=0;
scanf("%d",&n);
for (i=1;i<=n;i++){
scanf("%d",&k);
a[i]=k%7;
sum+=k%7;
}
m=n;
int t=sum;
while (t%7!=0 && m>0){
t-=a[m];
m--;
}
int maxn;
maxn=m;
m=1;
t=sum;
while (t%7!=0 && m<n){
t-=a[m];
m++;
}
m=n-m;
maxn=maxn>m?maxn:m;
m=n;
int x;
x=1;
t=sum;
while (t%7!=0 && m>0 && x<n){
t-=a[m];
if (t%7==0)
break;
t-=a[x];
m--;
x++;
}
t=m-x+1;
maxn=maxn>t?maxn:t;
if (maxn%10==5){
printf("%d\n",maxn);
return 0;
}
maxn+=3;
if (maxn%10==7) maxn++;
printf("%d\n",maxn);
return 0;
}
USACO2016 Jan Bronze 4:Promotion Counting
最新推荐文章于 2024-08-22 10:34:32 发布