Answer to Question #306810 in C for Mohammed

Question #306810

Harry likes candies and he cannot get satisfied with only the ones he buys from the stores. He knows one of the best places to get it a Candy warehoue Vie decades to raid the warehouse located in Mary-ville. The warehouse has m containers, in the ith container there are x i candy boxes each having yi candies. All candy bees are of the same size. Harry is carrying a rucksack which can hold n boxes. He needs to find out which boxes to pick up so that he gets the maximum number of candles in this raid







Can you help him pick up the boxes and report on how many maximum number of candies he could steal?







Input







First line contains integer n (1 <= n <= 2x10^8 ") and integer *m (1 <= m <= 20). The i+ 1th line contains a pair of numbers and yi[1<x< 10^81<=y_j<=10







Output







Single number for the number of candies.







Sample input







73







5 10







25







36

1
Expert's answer
2022-03-07T07:11:21-0500
#include <bits/stdc++.h>


using namespace std;


string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);


/*
 * Complete the 'twoRobots' function below.
 *
 * The function is expected to return an INTEGER.
 * The function accepts following parameters:
 *  1. INTEGER m
 *  2. 2D_INTEGER_ARRAY queries
 */


int twoRobots(int m, vector<vector<int>> queries) {


}


int main()
{
    ofstream fout(getenv("OUTPUT_PATH"));


    string t_temp;
    getline(cin, t_temp);


    int t = stoi(ltrim(rtrim(t_temp)));


    string first_multiple_input_temp;
    getline(cin, first_multiple_input_temp);


    vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp));


    int m = stoi(first_multiple_input[0]);


    int n = stoi(first_multiple_input[1]);


    vector<vector<int>> queries(n);


    for (int i = 0; i < n; i++) {
        queries[i].resize(2);


        string queries_row_temp_temp;
        getline(cin, queries_row_temp_temp);


        vector<string> queries_row_temp = split(rtrim(queries_row_temp_temp));


        for (int j = 0; j < 2; j++) {
            int queries_row_item = stoi(queries_row_temp[j]);


            queries[i][j] = queries_row_item;
        }
    }


    int result = twoRobots(m, queries);


    fout << result << "\n";


    fout.close();


    return 0;
}


string ltrim(const string &str) {
    string s(str);


    s.erase(
        s.begin(),
        find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
    );


    return s;
}


string rtrim(const string &str) {
    string s(str);


    s.erase(
        find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
        s.end()
    );


    return s;
}


vector<string> split(const string &str) {
    vector<string> tokens;


    string::size_type start = 0;
    string::size_type end = 0;


    while ((end = str.find(" ", start)) != string::npos) {
        tokens.push_back(str.substr(start, end - start));


        start = end + 1;
    }


    tokens.push_back(str.substr(start));


    return tokens;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS