CREDCOINS - Editorial

PROBLEM LINK:

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

Setter: Kanhaiya Mohan
Tester: Manan Grover
Editorialist: Prakhar Kochar

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

For each bill you pay using CRED, you earn X CRED coins. At CodeChef store, each bag is worth 100 CRED coins.

Chef pays Y number of bills using CRED. Find the maximum number of bags he can get from the CodeChef store.

EXPLANATION:

We know that Chef pays Y number of bills. With each bill Chef earns X CRED coins.

After paying all the Y bills Chef earns X \cdot Y CRED coins.

We know each bag is worth 100 CRED coins. Therefore with X \cdot Y CRED coins chef can get maximum \lfloor \frac{X \cdot Y}{100} \rfloor bags.

Here, \lfloor N \rfloor is floor(N) which represents the largest integer less than or equal to N.

Examples
  • X = 10, Y = 11;
    \lfloor \frac{110}{100} \rfloor = 1. Therefore, Chef can buy maximum 1 bag

  • X = 80, Y = 10;
    \lfloor \frac{800}{100} \rfloor = 8. Therefore, Chef can buy maximum 8 bags

TIME COMPLEXITY:

O(1) for each test case.

SOLUTION:

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

long long readInt(long long l, long long r, char endd) {
    long long x = 0;
    int cnt = 0;
    int fi = -1;
    bool is_neg = false;
    while (true) {
        char g = getchar();
        if (g == '-') {
            assert(fi == -1);
            is_neg = true;
            continue;
        }
        if ('0' <= g && g <= '9') {
            x *= 10;
            x += g - '0';
            if (cnt == 0) {
                fi = g - '0';
            }
            cnt++;
            assert(fi != 0 || cnt == 1);
            assert(fi != 0 || is_neg == false);
 
            assert(!(cnt > 19 || (cnt == 19 && fi > 1)));
        }
        else if (g == endd) {
            assert(cnt > 0);
            if (is_neg) {
                x = -x;
            }
            assert(l <= x && x <= r);
            return x;
        }
        else {
            assert(false);
        }
    }
}
int main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  int t;
  t = readInt(1, 100, '\n');
  while(t--){
    int x, y;
    x = readInt(1, 1000, ' ');
    y = readInt(1, 1000, '\n');
    cout<<(x * y) / 100<<"\n";
  }
  return 0;
}
Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define inf INT_MAX
#define mod 998244353

void f() {
    int x, y;
    cin >> x >> y;
    cout << (y * x) / 100 << "\n";
}

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while (t--) f();
}
5 Likes