XMAS20 - Editorial

PROBLEM LINK:

Contest

Setter: aviroop001

Tester: debrc , mishra_roshan

Editorialist: aviroop001

DIFFICULTY:

Simple

PREREQUISITES:

Basic observations, Comparisons

PROBLEM:

Impish or Admirable is a tradition form south-western Germany, in which children receive cash gifts from Belsnickel- another form of Santa.

Belsnickel especially loves three children from The Schrute Farms, namely Dwight, Mose and Fannie and he wants to give them cash gifts. The oldest child, Dwight, proposes that a distribution of money is fair only if an older descendant always receives more money than any younger sibling; if two siblings share the same age, they should receive the same amounts of cash reward.

For each valid child, the n^t child is age_n years old and received cash_n cash as reward. Determine whether this distribution of money is in terms with Dwight Schrute.

EXPLANATION

The basic concept behind the solution is to compare the cash reward each child is getting. We compare a cash prize with the other cash prizes and the respective ages of the children, if it does not fit our criteria, we can simply print NO, else YES.

SOLUTIONS:

Setter's Solution
C++
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t, a[3], c[3];
    cin >> t;
    while (t){
        for (int i = 0; i < 3; i++)
            cin >> a[i];
        for (int i = 0; i < 3; i++)
            cin >> c[i];
        bool flag = true;
        if (a[1] > a[0]){
            if (c[1] <= c[0]){
                cout << "NO";
                flag = false;
            }
        }
        else if (a[1] < a[0]){
            if (c[1] >= c[0]){
                cout << "NO";
                flag = false;
            }
        }
        else{
            if (c[1] != c[0]){
                cout << "NO";
                flag = false;
            }
        }
        if (flag){
            if (a[2] > a[1]){
                if (c[2] <= c[1]){
                    cout << "NO";
                    flag = false;
                }
            }
            else if (a[2] < a[1]){
                if (c[2] >= c[1]){
                    cout << "NO";
                    flag = false;
                }
            }
            else{
                if (c[2] != c[1]){
                    cout << "NO";
                    flag = false;
                }
            }
        }
        if (flag){
            if (a[2] > a[0]){
                if (c[2] <= c[0]){
                    cout << "NO";
                    flag = false;
                }
            }
            else if (a[2] < a[0]){
                if (c[2] >= c[0]){
                    cout << "NO";
                    flag = false;
                }
            }
            else{
                if (c[2] != c[0]){
                    cout << "NO";
                    flag = false;
                }
            }
        }
        if (flag)
            cout << "YES";
        if (t != 1)
            cout << endl;
        t--;
    }
    return 0;
}


Feel free to Share your thought process .
Suggestions are welcomed as always had been.