Advertisement
YEZAELP

PROG-1127: number

Apr 6th, 2021
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int INF = 2e9;
  5. using pi = pair <int, int>;
  6. pi ar[10]; // price, value
  7.  
  8. int main(){
  9.  
  10.     int money, mn = INF;
  11.     scanf("%d", &money);
  12.  
  13.     for(int i=1;i<=9;i++){
  14.         int price;
  15.         scanf("%d", &price);
  16.         mn = min(mn, price);
  17.         ar[i] = {price, i};
  18.     }
  19.  
  20.     int digit = money/mn;
  21.     while(digit--){
  22.         int mx = 0, idx;
  23.         for(int i=1;i<=9;i++){
  24.             if(money - digit*mn - ar[i].first >= 0){
  25.                 if(ar[i].second > mx){
  26.                     mx = ar[i].second;
  27.                     idx = i;
  28.                 }
  29.             }
  30.         }
  31.         printf("%d", mx);
  32.         money = money - ar[idx].first;
  33.     }
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
RAW Paste Data Copied
Advertisement