POPULATION - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: Abhinav Gupta
Testers: Abhinav Sharma, Venkata Nikhil Medam
Editorialist: Nishank Suresh

DIFFICULTY:

358

PREREQUISITES:

None

PROBLEM:

X million people live in a town. Of them, Y million leave and Z million enter. How many people are in the town now?

EXPLANATION:

There were initially X million people in the town. After Y million leave, there were X - Y million people in it. After Z million entered, there are X - Y + Z million people in it. Thus, the solution is to print X - Y + Z.

TIME COMPLEXITY:

\mathcal{O}(1) per test case.

CODE:

Tester (C++)
// Tester: Nikhil_Medam
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"

int t, x, y, z;
int32_t main() {
    cin >> t;
    while(t--) {
        cin >> x >> y >> z;
        cout << x - y + z << endl;
    }
	return 0;
}

Editorialist (Python)
for _ in range(int(input())):
    x, y, z = map(int, input().split())
    print(x - y + z)