1334A - Level Statistics - CodeForces Solution


implementation math *1200

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    p, c = [], []

    for i in range(n):
        x, y = map(int, input().split())
        p.append(x)
        c.append(y)

    t = 'YES'
    for i in range(1, n):
        x = p[i] - p[i-1]
        y = c[i]-c[i-1]
        
        if x < y:
            t = 'NO'
            break
        elif x < 0 or y < 0:
            t = 'NO'
            break
        
    x = p[0]
    y = c[0]
        
    if x < y:
        t = 'NO'
    elif x < 0 or y < 0:
        t = 'NO'
    print(t)

C++ Code:

#include <bits/stdc++.h>

using namespace std;

int main() 
{
    int t; cin >>t;
    while (t--)
    {
      int n; cin >>n;
      int x[n],y[n];
      
      for (int i=0;i<n;i++)
      cin >>x[i]>>y[i];
      
      int c=0;
      if (x[0]<y[0])
      c++;
      
      for (int i=1;i<n;i++)
      {
        if (x[i]<x[i-1] || y[i]<y[i-1] || y[i]>x[i] || x[i]-x[i-1]<y[i]-y[i-1])
        c++;
      }
      
      c>0 ? cout <<"NO\n" : cout <<"YES\n";
    }
    
    
    
    return 0;
}


Comments

Submit
0 Comments
More Questions

579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold