环形跑道

来源:互联网 发布:ubuntu 16.04 wine qq 编辑:程序博客网 时间:2024/04/28 18:04
// 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;}

0 0
原创粉丝点击