fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int compare(pair<int, int> a, pair<int, int> b){
  5. if(a.first > b.first)
  6. return 0;
  7. return 1;
  8. }
  9.  
  10. long buyMaximumProducts(int n, long k, vector <int> a) {
  11. // Complete this function
  12. long ans = 0;
  13. vector< pair<int,int> > v;
  14. for(int i = 0; i < n; i++){
  15. v.push_back( pair<int, int> {a[i], i+1} );
  16. }
  17. sort(v.begin(), v.end(), compare);
  18. for(int i = 0; i < n && k > 0; i++){
  19. if(k>= (v[i].first)*(v[i].second)){
  20. ans+= v[i].second;
  21. k-= (v[i].first)*(v[i].second);
  22. }
  23. else{
  24. int temp= k/(v[i].first);
  25. ans+= temp;
  26. k-= (v[i].first)*temp;
  27. }
  28. }
  29. return ans;
  30. }
  31.  
  32. int main() {
  33. int n;
  34. cin >> n;
  35. vector<int> arr(n);
  36. for(int arr_i = 0; arr_i < n; arr_i++){
  37. cin >> arr[arr_i];
  38. }
  39. long k;
  40. cin >> k;
  41. long result = buyMaximumProducts(n, k, arr);
  42. cout << result << endl;
  43. return 0;
  44. }
  45.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
1 10 7 19
compilation info
prog.cpp: In function 'long int buyMaximumProducts(int, long int, std::vector<int, std::allocator<int> >)':
prog.cpp:15: error: expected primary-expression before '{' token
stdout
Standard output is empty