int n, t;
first while(cin >> n)
and then if (n == 0)break
cin >> t
vector<long long int>a(t + 1, 0)
....
....
....省
....略
....了
....
....
if (c == -1)
ans = false;
else
a[c] = x;
printf("%s\n", ans ? " YES" : "NO");
that's all i can give you