Advertisement
Guest User

Employés - épreuve de sélection 2 France-IOI

a guest
Mar 3rd, 2019
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define chmin(x, v) x = min(x, v)
  3. #define chmax(x, v) x = max(x, v)
  4. using namespace std;
  5.  
  6. struct Employe
  7. {
  8.     int tache, coutChangement;
  9. };
  10.  
  11. int main()
  12. {
  13.     int nbEmployes, nbTaches;
  14.     cin >> nbEmployes >> nbTaches;
  15.     bool fait[nbTaches];for (int i=0;i<nbTaches;++i)fait[i]=false;
  16.     Employe p[nbEmployes];
  17.     int cost[nbTaches];
  18.     vector<int> sac;
  19.     for (int i=0;i<nbEmployes;++i)
  20.     {
  21.         cin >> p[i].tache;p[i].tache--;}
  22.     for (int i=0;i<nbEmployes;++i)
  23.         cin >> p[i].coutChangement;
  24.     for (int i=0;i<nbEmployes;++i)
  25.     {
  26.         if (!fait[p[i].tache])
  27.         {
  28.             fait[p[i].tache] = true;
  29.             cost[p[i].tache] = p[i].coutChangement;
  30.         }
  31.         else if ( cost[p[i].tache] < p[i].coutChangement)
  32.         {
  33.             sac.push_back(cost[p[i].tache]);
  34.             cost[p[i].tache] = p[i].coutChangement;
  35.         }
  36.         else
  37.         {
  38.             sac.push_back(p[i].coutChangement);
  39.         }
  40.     }
  41.     sort(sac.begin(), sac.end());
  42.     long long tot = 0;
  43.     int pointeur = 0;
  44.     for (int idTache = 0; idTache < nbTaches; ++idTache)
  45.     {
  46.         if ( !fait[idTache])
  47.         {
  48.             tot += sac[pointeur];
  49.             pointeur++;
  50.         }
  51.     }
  52.     cout << tot << endl;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement