uva11093 Just Finish it up
#include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1000100; const int INF=1<<29; int n; ll p[maxn],q[maxn]; int main() { freopen("in.txt","r",stdin); int T;cin>>T;int casen=1; while(T--){ scanf("%d",&n); REP(i,0,n-1) scanf("%lld",&p[i]); REP(i,0,n-1) scanf("%lld",&q[i]); int st=0,ans=-1; while(st<n){ ll s=0; bool flag=1; int k=0; REP(j,0,n-1){ s+=p[(st+j)%n]; //cout<<st+j<<endl; //cout<<"s="<<s<<" "<<q[(st+j)%n]<<endl; if(s>=q[(st+j)%n]) s-=q[(st+j)%n]; else{ k=j; flag=0;break; } } //cout<<"st="<<st<<" flag="<<flag<<endl; if(flag){ ans=st+1;break; } st=st+k+1; } printf("Case %d: ",casen++); if(ans==-1) puts("Not possible"); else printf("Possible from station %d\n",ans); } return 0; } /** why am I so stupid???!!! */
没有AC不了的题,只有不努力的ACMER!