AOJ - Problem 0033 : Ball

適当に試行錯誤してAcceptしました。無駄な処理を含んでいる気がします。

#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main(){
	int n, a;
	vector<int> A;
	cin >> n;
	
	for(int i=0 ; i<n ; i++){
		A.clear();
		for(int j=0 ; j<10 ; j++){
			cin >> a;
			A.push_back(a);
		}
		stack<int> B, C;
		bool flag = true;
		B.push(0);
		C.push(0);
		for(int j=0 ; j<10 ; j++){
			a = A[j];
			if( B.top() == 0 ){
				B.push( a );
			}else{
				if( B.top() > a ){
					if( C.top() > a ){
						cout << "NO" << endl;
						flag = false;
						break;
					}else{
						C.push(a);
					}
				}else{
					if( C.top() > a ){
						B.push(a);
					}else{
						( a-B.top() < a-C.top() )? B.push(a) : C.push(a) ;
					}
				}
			}
		}
		if( flag ){
			cout << "YES" << endl;
		}
	}
}