Блог пользователя joyz09

Автор joyz09, история, 15 месяцев назад, По-английски
#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://codeforces.me/problemset/problem/2128/C

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

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

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.