Edward is playing a simplified version of the game called "Dorsplen". This game is played with gems of three different colors: red, green and blue. Initially player has no gem and there are infinitely many gems of each color on the table.
On each turn a player can either acquire gems or buy an artifact. Artifact can be bought using gems. On acquiring gems player can get three gems of distinct colors or two gems of the same color from the table.
Edward is planning to buy an artifact, it costs r red gems, g green gems and b blue gems. Compute, what is the minimum number of turns Edward has to make to earn at least r red gems, g green gems and b blue gems, so that he will be able to buy the artifact.
Example:
Input: a = {4,5,8}
Output: 4
Approach
C++
#include <bits/stdc++.h>using namespace std;long long dorsplen(long long a, long long b, long long c){long long turn = 0;turn += b;c = c - b;turn += ((c + 1) / 2);return turn;}int main(){long long a[3] = {4, 5, 8};sort(a, a + 3);cout << dorsplen(a[0], a[1], a[2]);return 0;}
No comments:
Post a Comment