joyz09's blog

By joyz09, history, 8 months ago, In English
#include <iostream>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        long m = (long)INT_MAX;
        while(n--){
            long b;
            cin >> b;
            if(b <= m){
                m = b;
            }else{
                if(b > 2*m-1){
                    cout << "NO" << endl;
                    break;
                }
            }
            if(n==0) cout << "YES" << endl;
        }
    }
    return 0;
}

https://mirror.codeforces.com/problemset/problem/2128/C

It always shows wrong in test case 2 token 46 The test case is n = 3 1 2 2

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
8 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

The break may causes your code to skip the rest of the inputs from previous testcase. For example let's say that the input is

2
3
1 2 1
3
1 2 2

Your code break from the loop at the second number from the first testcase, and then starts taking the input from the beginning. 1 is taken as n, and then you only take one number as b, that begin 1. So your code will output NO YES, despite the answer begin NO NO.