Advertisement
informaticage

Greedy implementation of the problem ois plugs

Jan 26th, 2024
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int numeroComputer, numeroPrese;
  9.     cin >> numeroComputer >> numeroPrese;
  10.  
  11.     vector<int> potenze(numeroComputer);
  12.     vector<string> prese(numeroComputer);
  13.  
  14.     for(int i = 0; i < potenze.size(); i++) {
  15.         cin >> potenze.at(i);
  16.     }
  17.  
  18.     for(int i = 0; i < potenze.size(); i++) {
  19.         cin >> prese.at(i);
  20.     }
  21.  
  22.     size_t L10 = 0, L16 = 0, bipasso = 0;
  23.     for(int i = 0; i < numeroPrese; i++) {
  24.         string presaInput;
  25.         cin >> presaInput;
  26.  
  27.         if(presaInput == "L10") L10 ++;
  28.         if(presaInput == "L16") L16 ++;
  29.         if(presaInput == "bipasso") bipasso ++;
  30.     }
  31.  
  32.     vector<int> L10List, L16List;
  33.  
  34.     for(int i = 0; i < potenze.size(); i++) {
  35.         if(prese[i] == "L10") {
  36.             L10List.push_back(potenze[i]);
  37.         }
  38.  
  39.         if(prese[i] == "L16") {
  40.             L16List.push_back(potenze[i]);
  41.         }
  42.     }
  43.  
  44.     sort(L10List.begin(), L10List.end(), greater<int>());
  45.     sort(L16List.begin(), L16List.end(), greater<int>());
  46.  
  47.     int sum = 0;
  48.     for(int i = 0; i < min(L10, L10List.size()); i++) {
  49.         sum = sum + L10List.at(i);
  50.     }
  51.  
  52.     for(int i = 0; i < L16List.size(); i++) {
  53.         sum = sum + L16List.at(i);
  54.     }
  55.  
  56.     vector<int> avanzo;
  57.  
  58.     for(int i = L10; i < L10List.size(); i++) {
  59.         avanzo.push_back(L10List.at(i));
  60.     }
  61.  
  62.     for(int i = L16; i < L16List.size(); i++) {
  63.         avanzo.push_back(L16List.at(i));
  64.     }
  65.  
  66.     sort(avanzo.begin(), avanzo.end(), greater<int>());
  67.  
  68.     for(int i = 0; i < min(bipasso, avanzo.size()); i++) {
  69.         sum = sum + avanzo.at(i);
  70.     }
  71.  
  72.     cout << sum;
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement