Advertisement
AlenAntonelli

B. Color the Fence

Jul 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. /// https://trello.com/c/uaE7ki6J/4-problem-b-codeforces
  2. /// http://codeforces.com/contest/349/problem/B
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. int n;
  9. vector<int> v (10);
  10.  
  11. string resultado ()
  12. {
  13.     int num_base = 1;
  14.    
  15.     for (int i=1; i<10; i++)
  16.         if (v[i] <= v[num_base])
  17.             num_base = i;
  18.            
  19.     ///cout<<num_base<<endl;
  20.            
  21.     int cant_base = n/v[num_base];
  22.     int cant_mejorables = cant_base;
  23.     int sobra = n%v[num_base];
  24.    
  25.     if ( !cant_base )
  26.         return "-1";
  27.        
  28.     string resp;
  29.     for (int i=9; i>num_base; i--)
  30.     {
  31.         int costo = v[i] - v[num_base];
  32.         if (sobra >= costo)
  33.         {
  34.             int mejoro = sobra/costo;
  35.            
  36.             for (int j=0; j<mejoro && j<cant_mejorables; j++)
  37.                 resp+= i+'0';
  38.                
  39.             cant_mejorables-=mejoro;
  40.             sobra = sobra%costo;
  41.         }
  42.     }
  43.    
  44.     for (int i=0; i<cant_mejorables; i++)
  45.         resp+= num_base+'0';
  46.        
  47.     return resp;
  48. }
  49.  
  50. int main()
  51. {
  52.     cin>>n;
  53.    
  54.     for (int i=1; i<10; i++)
  55.         cin>>v[i];
  56.    
  57.     cout<<resultado();
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement