USACO2016 Jan Bronze 4:Promotion Counting

来源:互联网 发布:mysql持久化是什么 编辑:程序博客网 时间:2024/05/22 10:07
#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;}

0 0
原创粉丝点击