Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fi first
- #define se second
- using namespace std;
- using i64 = long long;
- void solve() {
- int n; cin >> n;
- vector<i64> a(n-1);
- map<int, int> freq;
- for (int i = 0; i < n-1; ++i) {
- cin >> a[i];
- ++freq[i == 0 ? a[i] : a[i] - a[i-1]];
- }
- // verificar se removeu do fim
- vector<int> faltando;
- int cntFreq = 0, hasRepeated = false;
- for (int i = 1; i <= n; ++i) {
- if (freq[i]) {
- if (freq[i] > 1) hasRepeated = true;
- ++cntFreq;
- }
- else {
- faltando.push_back(i);
- }
- }
- if (cntFreq == n-1 and !hasRepeated) {
- cout << "YES\n";
- return;
- }
- // verificar se removeu do começo
- if (cntFreq == n-2 and faltando.size() == 2 and faltando[0] + faltando[1] == a[0] and !hasRepeated) {
- cout << "YES\n";
- return;
- }
- // verificar se removeu do meio
- if (cntFreq == n-2 and faltando.size() == 2 and (faltando[0] + faltando[1] <= n ? freq[faltando[0] + faltando[1]] == 2 : freq[faltando[0] + faltando[1]] == 1)) {
- cout << "YES\n";
- return;
- }
- cout << "NO\n";
- }
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- int tc; cin >> tc;
- while (tc--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment