Advertisement
tepyotin2

Race Car Upgrade

Jan 17th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int F, M, N;
  6.  
  7. struct Items{
  8.     int f;
  9.     int m;
  10.     int id;
  11.     Items(){};
  12.     Items(int f1, int m1, int id1){
  13.         f = f1;
  14.         m = m1;
  15.         id = id1;
  16.     };
  17. };
  18.  
  19. bool comp(Items a, Items b){
  20.     return a.f*b.m > a.m * b.f;
  21. }
  22.  
  23. int main(){
  24.     ios_base::sync_with_stdio(0), cin.tie(0);
  25.     // freopen("rcupgrade.in", "r", stdin);
  26.     cin >> F >> M >> N;
  27.     int a, b;
  28.     Items item[N];
  29.     for(int i=0; i<N; i++){
  30.         cin >> a >> b;
  31.         item[i].f = a;
  32.         item[i].m = b;
  33.         item[i].id = i+1;
  34.     }
  35.     sort(item, item+N, comp);
  36.     int res[N];
  37.     int count = 0;
  38.     for(int i=0; i<N; i++){
  39.         int f = item[i].f;
  40.         int m = item[i].m;
  41.         if(F*m < M*f){
  42.             res[count] = item[i].id;
  43.             // cout << "i: " << i << ", item: " << item[i].id << ", force: " << item[i].f << ", mass: " << item[i].m << '\n';
  44.             count++;
  45.             F+=f;
  46.             M+=m;
  47.         }
  48.     }
  49.     if(count == 0){
  50.         cout << "NONE" << '\n';
  51.     }else{
  52.         sort(res, res+count);
  53.         for(int i=0; i<count; i++){
  54.             cout << res[i] << '\n';
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement