纸上模拟下,容易发现结论。
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <algorithm>
#define SF(a) scanf("%d", &a)
#define PF(a) printf("%d\n", a)
#define SFF(a, b) scanf("%d%d", &a, &b)
#define SFFF(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SFFFF(a, b, c, d) scanf("%d%d%d%d", &a, &b, &c, &d)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define LL long long
#define maxn 100005
#define maxm 205
#define mod 1000000007
#define INF 1000000007
#define eps 1e-4
using namespace std;
int buf[20], l;
int read() {
int x = 0; char ch = getchar(); bool f = 0;
while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = getchar(); }
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
void write(int x) {
if (!x) { putchar(48); return; }
l = 0; if (x < 0) putchar('-'), x = -x;
while (x) buf[++l] = x % 10, x = x / 10;
while (l) putchar(buf[l--] + 48);
}
//-------------------------CHC------------------------------//
int p[maxn], q[maxn], n;
int check(int i) {
int cnt = n;
int sum = 0;
bool last = false;
while (cnt--) {
sum += p[i] - q[i];
if (sum < 0) {
if(last) return -2;
return i;
}
if ((i + 1) >= n) last = true;
i = (i + 1) % n;
}
return -1;
}
int solve() {
FOR(i, 0, n) {
int res = check(i);
if (res >= 0) i = res;
else if (res == -1) return i;
else break;
}
return -1;
}
int main() {
int t, kase = 1;
t = read();
while (t--) {
n = read();
FOR(i, 0, n) p[i] = read();
FOR(i, 0, n) q[i] = read();
int ans = solve();
printf("Case %d: ", kase++);
if (ans < 0) puts("Not possible");
else printf("Possible from station %d\n", ans + 1);
}
return 0;
}