C. Element Extermination
Problem
I could not solve problem A, so I have no rating change in this contest :(
You are given an array of permutation of .
You can perform the following operation any number of time :
choose two-element such that , and remove or .
if you can make array length 1, print "YES".
Solution
単調増加部分列であれば、任意の要素を残すことができる。
例えば、 [4 5 6 7 ] → [4 5 7] → [4,7 ]→[7]みたいにな感じ。
与えられた数列を単調増加列に分ける。を連続増加列として、 とする。
さて、右から左に向かって数列をマージ(?)していくことを考える。
に操作を適用する。このとき、が成り立てば、操作を適用することでをとすることができる。
さらに、明らかにであることから、これらを考えると条件はのときYes.
#include<bits/stdc++.h> using namespace std; inline int solve(){ int N; cin >> N; vector<int>A(N); for(auto& e : A) cin >> e; cout << (A.front() < A.back() ? "YES" : "NO") << endl; return 0; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int Q = 1; cin >> Q; while(Q--){solve();} }