Advertisement
CiprianOlaru

That ecology problem

Dec 6th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int V;
  6.     cin >> V;
  7.    
  8.     int UmgA[101], UmgB[101];
  9.     int total;
  10.     cin >> total;
  11.     for (int i = 1; i <= total; ++i)
  12.         cin >> UmgA[i];
  13.     for (int i = 1; i <= total; ++i)
  14.         cin >> UmgB[i];
  15.        
  16.     int PA, PB;
  17.     cin >> PA >> PB;
  18.    
  19.     float EfA[101], EfB[101];
  20.     for (int i = 1; i <= total; ++i) {
  21.         EfA[i] = (float)(UmgA[i] / PA);
  22.         EfB[i] = (float)(UmgB[i] / PB);
  23.     }
  24.    
  25.     int choicesA = 0, choicesB = 0;
  26.     int pozA = 1, pozB = 1;
  27.     int Vcopy = V;
  28.    
  29.     while (V > PA && V > PB) {
  30.         if (EfA[pozA] > EfB[pozB]) {
  31.             ++choicesA;
  32.             V -= PA;
  33.             ++pozA;
  34.         } else if (EfA[pozA] == EfB[pozB]) {
  35.             if (PA < PB) {
  36.                 ++choicesA;
  37.                 V -= PA;
  38.                 ++pozA;
  39.             } else {
  40.                 ++choicesB;
  41.                 V -= PB;
  42.                 ++pozB;
  43.             }
  44.         } else {
  45.             ++choicesB;
  46.             V -= PB;
  47.             ++pozB;
  48.         }
  49.     }
  50.    
  51.     int Pr = choicesA * PA + choicesB * PB + V;
  52.     cout << choicesA << " " << PA << endl;
  53.     cout << choicesB << " " << PB << endl;
  54.     cout << V << endl;
  55.     cout << Pr << endl;
  56.    
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement