// by BNU_LZM
#include<cstdio>
const int maxn = 100000+10;
int n, p[maxn], a[maxn];
int main()
{
freopen("in.txt", "r", stdin);
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &p[i]);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
int s = 1, okok = 0;
for(;;)
{
int pe = p[s], i = s, ok = 0, tot = 0;
while(pe >= a[i])
{
if(i == s && tot == n) {ok = 1; break;}
pe -= a[i];
i = i%n + 1; tot++;
pe += p[i];
}
if(ok)
{
printf("Possible from station %d\n", s);
okok = 1;
break;
}
s += (tot+1);
if(s > n) break;
}
if(!okok)
{
printf("Not possible\n");
}
}
return 0;
}
环形跑道
最新推荐文章于 2020-12-26 10:09:25 发布