WHATSAPP-Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Tejas Pandey
Tester: Satyam, Utkarsh Gupta
Editorialist: Devendra Singh

DIFFICULTY:

To be calculated

PREREQUISITES:

None

PROBLEM:

Chef recently installed Whatsapp on his mobile device. Currently, he has no unread messages.

Every hour he receives X messages and he is able to read Y messages out of them. After some time Chef notices that he has some unread messages.

Can you tell him exactly how many unread messages Chef has after Z hours have passed.

EXPLANATION:

Every hour chef receives X messages and he is able to read Y messages out of them. This means every hour X-Y messages are left unread by chef. Therefore for Z hours, total number of unread messages is Z\cdot (X-Y).

TIME COMPLEXITY:

O(1) or for each test case.

SOLUTION:

Setter's solution
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    assert(t > 1 && t < 20001);
    while(t--) {
        int x, y, k;
        cin >> x >> y >> k;
        assert(1 <= x && x <= 50);
        assert(1 <= y && y <= x);
        assert(1 <= k && k <= 10);
        cout << (x - y)*k << "\n";
    }
}
Editorialist's Solution
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(), _obj.end()
#define F first
#define S second
#define pll pair<ll, ll>
#define vll vector<ll>
ll INF = 1e18;
const int N = 1e5 + 11, mod = 1e9 + 7;
ll max(ll a, ll b) { return ((a > b) ? a : b); }
ll min(ll a, ll b) { return ((a > b) ? b : a); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void sol(void)
{
    int x, y, z;
    cin >> x >> y >> z;
    cout << z * (x - y) << '\n';
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int test = 1;
    cin >> test;
    while (test--)
        sol();
}