Creatnx now wants to decorate his house with flower pots. He plans to buy exactly N ones. He can only buy them from Triracle's shop. There are only two kinds of flower pots available in that shop. The shop is very strange. If you buy
flower pots of kind 1 then you must pay and if you buy flower pots of kind 2. Please help Creatnx buys exactly flower pots that minimize money he pays.
Example:
Input: n = 5, a = 1, b = 2
Output: 17
Approach
C++
#include <bits/stdc++.h>using namespace std;void specialShop(long long n, long long a,long long b){double p = (double)(n * b) / (a + b);p = round(p);long long ans = p * p * a + (n - p) * (n - p) * b;cout << ans << "\n";}int main(){long long n = 5, a = 1, b = 2;specialShop(n, a, b);return 0;}
No comments:
Post a Comment