0

Why did my private test cases fail ?

IronMan is stuck on a level of the Infinity War game which he is playing now. To advance this level, he has to kill all the N dragons that are present on this level. IronMan and the dragons have strength, which is represented by an integer. In the fight between him and dragon, the fight's outcome is determined by their strength. Initially, IronMan's strength equals S. If IronMan starts dueling with the ith (1 <= i <= N) dragon and IronMan's strength is not greater than the dragon's strength Xi, then IronMan loses the duel and dies. But if IronMan's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by Yi. IronMan can fight the dragons in any order. Your task is to find out if he will be able to win all the duels without any loss. Input Format: The first line will contain two space-separated integers, the initial strength S and the number of dragons N. Then N lines follow, each of which contains two space-separated integers Xi and Yi, where Xi is the strength of the dragon and Yi is the bonus strength which IronMan gains after defeating this dragon. Output Format: Print a single line containing either "YES" (without quotes), if IronMan can defeat all dragons or "NO" (without quotes) if he can't. For example: Input: 2 2 1 99 100 0 Output: YES Explanation: IronMan's initial strength is 2 and the number of dragons also equals 2 The first dragon has strength equal to 1 and thus IronMan can defeat this dragon and gain 99 points making his strength equal to 2 + 99 = 101. Since 101 > 100, IronMan can defeat this dragon also and thus the answer is YES. This is my code: #include<iostream> using namespace std; int main(){ int s{0}; int n{0}; bool c{true}; cin >> s >> n; while(n--){ int a; int b; cin >> a >> b; if(s>a){ s = s + b; } else{ cout << "NO"; c = false; break;}} if(c == true){ cout << "YES";}}

26th Nov 2022, 8:49 AM
Krishna Sarawagi
Krishna Sarawagi - avatar
1 Odpowiedź
+ 2
Your code seems to be incomplete. Please save it in the code playground, and provide a link in comment, so it could be tested easily by those who would like to help.
26th Nov 2022, 8:54 AM
Tibor Santa
Tibor Santa - avatar