Codechef Problems: Movie (MOVIE7)
Problem Statement:
Solution:
Given,
N : number of movie tickets
M : number of popcorn buckets
A : Price of a movie ticket
B : Price of a popcorn bucket
C : Special combined price of a movie ticket and a popcorn bucket
to find: minimum amount chef needs to spend
condition 1 : N >= M (i.e., number of movie tickets is more than popcorn buckets)
in this case chef can get at most buy M special price benefit offer and remaining (N-M) tickets has be bought at original movie ticket price A
so minimum amount = M * C + (N - M) * A
condition 2: N < M (i.e., number of popcorn buckets is more than movie tickets)
in this case chef can get at most buy N special price benefit offer and remaining (M - N) popcorn buckets has to be bought at the original popcorn bucket price B
so minimum amount = N * C + (M - N) * B
Code Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int a, b, c, n, m;
while (t--) {
cin >> n >> m >> a >> b >> c;
if (n >= m) {
cout << m * c + (n - m) * a << endl;
} else {
cout << (n * c) + (m - n) * b << endl;
}
}
return 0;
}
Comments
Post a Comment