https://w...content-available-to-author-only...k.com/contests/hack-the-interview-ii-global/challenges/distribution-in-m-bins/submissions/code/1323377015#include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); vector<string> split(const string &); /* * Complete the 'maxScore' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER_ARRAY a * 2. INTEGER m */ int maxScore(vector<int> arr, int m) { int n = arr.size(); sort(arr.begin(), arr.end()); long long ans = 0; int seg_num = 1, seg_size = 0; map <int, long long> segments; for (int i = 0; i < n; i++) { if (seg_size < m) { seg_size++; } else { seg_num++; seg_size = 1; } segments[seg_num] += arr[i]; } if (seg_size < m) { segments[seg_num - 1] += segments[seg_num]; segments[seg_num] = 0; } int cnt = 1; for (auto it = segments.begin(); it != segments.end(); it++, cnt++) { ans += (cnt * it->second) % 1000000007LL; } return ans; } int main() { ofstream fout(getenv("OUTPUT_PATH")); string first_multiple_input_temp; getline(cin, first_multiple_input_temp); vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp)); int n = stoi(first_multiple_input[0]); int m = stoi(first_multiple_input[1]); string a_temp_temp; getline(cin, a_temp_temp); vector<string> a_temp = split(rtrim(a_temp_temp)); vector<int> a(n); for (int i = 0; i < n; i++) { int a_item = stoi(a_temp[i]); a[i] = a_item; } int ans = maxScore(a, m); fout << ans << "\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; }
Standard input is empty
prog.cpp:1:1: error: ‘https’ does not name a type https://www.hackerrank.com/contests/hack-the-interview-ii-global/challenges/distribution-in-m-bins/submissions/code/1323377015#include <bits/stdc++.h> ^~~~~ prog.cpp:5:1: error: ‘string’ does not name a type; did you mean ‘struct’? string ltrim(const string &); ^~~~~~ struct prog.cpp:6:1: error: ‘string’ does not name a type; did you mean ‘struct’? string rtrim(const string &); ^~~~~~ struct prog.cpp:7:1: error: ‘vector’ does not name a type vector<string> split(const string &); ^~~~~~ prog.cpp:18:14: error: ‘vector’ was not declared in this scope int maxScore(vector<int> arr, int m) { ^~~~~~ prog.cpp:18:21: error: expected primary-expression before ‘int’ int maxScore(vector<int> arr, int m) { ^~~ prog.cpp:18:31: error: expected primary-expression before ‘int’ int maxScore(vector<int> arr, int m) { ^~~ prog.cpp:18:36: error: expression list treated as compound expression in initializer [-fpermissive] int maxScore(vector<int> arr, int m) { ^ prog.cpp: In function ‘int main()’: prog.cpp:60:5: error: ‘ofstream’ was not declared in this scope ofstream fout(getenv("OUTPUT_PATH")); ^~~~~~~~ prog.cpp:62:5: error: ‘string’ was not declared in this scope string first_multiple_input_temp; ^~~~~~ prog.cpp:62:5: note: suggested alternative: ‘struct’ string first_multiple_input_temp; ^~~~~~ struct prog.cpp:63:13: error: ‘cin’ was not declared in this scope getline(cin, first_multiple_input_temp); ^~~ prog.cpp:63:13: note: suggested alternative: ‘main’ getline(cin, first_multiple_input_temp); ^~~ main prog.cpp:63:18: error: ‘first_multiple_input_temp’ was not declared in this scope getline(cin, first_multiple_input_temp); ^~~~~~~~~~~~~~~~~~~~~~~~~ prog.cpp:63:5: error: ‘getline’ was not declared in this scope getline(cin, first_multiple_input_temp); ^~~~~~~ prog.cpp:65:5: error: ‘vector’ was not declared in this scope vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp)); ^~~~~~ prog.cpp:65:20: error: ‘first_multiple_input’ was not declared in this scope vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp)); ^~~~~~~~~~~~~~~~~~~~ prog.cpp:65:49: error: ‘rtrim’ was not declared in this scope vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp)); ^~~~~ prog.cpp:65:43: error: ‘split’ was not declared in this scope vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp)); ^~~~~ prog.cpp:67:13: error: ‘stoi’ was not declared in this scope int n = stoi(first_multiple_input[0]); ^~~~ prog.cpp:67:13: note: suggested alternative: ‘std’ int n = stoi(first_multiple_input[0]); ^~~~ std prog.cpp:71:11: error: expected ‘;’ before ‘a_temp_temp’ string a_temp_temp; ^~~~~~~~~~~~ ; prog.cpp:72:18: error: ‘a_temp_temp’ was not declared in this scope getline(cin, a_temp_temp); ^~~~~~~~~~~ prog.cpp:74:20: error: ‘a_temp’ was not declared in this scope vector<string> a_temp = split(rtrim(a_temp_temp)); ^~~~~~ prog.cpp:76:12: error: expected primary-expression before ‘int’ vector<int> a(n); ^~~ prog.cpp:81:9: error: ‘a’ was not declared in this scope a[i] = a_item; ^ prog.cpp:84:24: error: ‘a’ was not declared in this scope int ans = maxScore(a, m); ^ prog.cpp:84:28: error: ‘maxScore’ cannot be used as a function int ans = maxScore(a, m); ^ prog.cpp:86:5: error: ‘fout’ was not declared in this scope fout << ans << "\n"; ^~~~ prog.cpp:86:5: note: suggested alternative: ‘float’ fout << ans << "\n"; ^~~~ float prog.cpp: At global scope: prog.cpp:93:1: error: ‘string’ does not name a type; did you mean ‘struct’? string ltrim(const string &str) { ^~~~~~ struct prog.cpp:104:1: error: ‘string’ does not name a type; did you mean ‘struct’? string rtrim(const string &str) { ^~~~~~ struct prog.cpp:115:1: error: ‘vector’ does not name a type vector<string> split(const string &str) { ^~~~~~
Standard output is empty