Five strongmen came to challenge Popeye. When packing up, Popeye needs to know how much spinach should he prepare. Each can of spinach will add one point to Popeye’s strength. To ensure that he can win all fights, Popeye’s strength point must be greater than the largest strength point among all the challengers.

Popeye’s initial strength point will always be smaller than or equal to the strongest challenger’s strength point.

Popeye’s strength point must be greater than his opponent’s strength point to secure victory.

The strength points are represented with integers.
Input
Six integers, a, b, c, d, e, and f, represent the strength points of Popeye and five challengers respectively. Popeye’s number is the first one.
Output
An integer indicating the least number of cans of spinach Popeye needed to win.
Sample Input
100 23 41 120 56 93
Sample Output
21
Constraints
0<=a,b,c,d,e,f<=1000
a<=max(b,c,d,e,f)
Hint
For the sample above, the largest strength point of the 5 challengers is 120. Popeye’s initial strength point is 100. So Popeye needs to eat 21 cans of spinach to have 121 strength points so he can defeat the strongest challenger.
Is this a question from CodinGame, Clash of Code? If so, you should solve these yourselves otherwise you ruin the fun for everyone. I would classify this as cheating and at the very least not in the spirit of Clash of Code.
1 Like
seems more like a codeforces question, tbh
EDIT: this comment is made as in the benefit of the doubt of the OP that they are doing this in practice mode, not in contest
HINT 1: find the largest number
HINT 2: this can be done using max(a, max(b, max(c, ...)))
(better way in next hint (HINT 3
))
HINT 3: but an even better way is to store the remaining non popeye values in a list and sort, choosing the last item (v.size()  1
or lst[1]
)
HINT 4: print(MAX  popeye)
SOLUTION:
c++:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int popeye;
const unsigned int num_rest = 5;
vector<int> rest(num_rest);
int main() {
cin.tie(0) > ios_base::sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> popeye;
for (auot& i : rest) cin >> i;
sort(rest.rbegin(), rest.rend());
cout << rest[0]  popeye;
}
python:
current_input = map(lamba x: int(x), input().split())
popeye = current_input[0]
rest = current_input[1:]
rest.sort(reverse=True)
print(rest[0]  popeye)
No this isn’t. Its for my hoomework. What’s CodingGame? or Clash of COde?
If it’s for school work we will not be able to help, sorry.
1 Like
Hi @Winstenna I really don’t think you should be posting your school assignment to this forum. It’s not right to expect others to do your homework for you and your tutor will not understand how to help you if you are submitting work from someone else.
Please feel free to post questions that will help you understand the building blocks of programs, but don’t post tasks again.
2 Likes
This topic was automatically closed 6 hours after the last reply. New replies are no longer allowed.