Bounty Mode- Editorial || BOUN

PROBLEM LINK: Bounty Mode | CodeChef

Problem Code: Bounty Mode | CodeChef

Practice: CodeChef | Competitive Programming | Participate & Learn | CodeChef

Contest : Campus Code Coding Competition | CodeChef

Author:* Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Tester: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Editorialist: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9

DIFFICULTY:

Easy

PREREQUISITES:

Basic Looping

PROBLEM:

PUBG has introduced a new bounty mode, in this mode every person has a bounty, you can kill any of the players to acquire the bounty on their head and use that money to buy gear. you want to buy a new gun which is k units in price. you have only two bullets left with you, given the bounties of each player find out whether you can kill any two players such that the sum of their bounties is equal to the price of your new gun.

EXPLANATION:
For example, given bounty list [10, 15, 3, 7] and price of gun 17, return true since 10 + 7 is 17.

SOLUTION:
C++:

#include <bits/stdc++.h>
using namespace std;

string result(int n, int k, vector vec){
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(vec[i]+vec[j]==k)
return “true”;
}
}
return “false”;
}
int main() {
int k; cin>>k;
int n; cin>>n;
vector vec(n);
for(int i=0; i<n; i++){
cin>>vec[i];
}
string result2=result(n,k,vec);
cout<<result2;

return 0;

}