Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// https://trello.com/c/uaE7ki6J/4-problem-b-codeforces
- /// http://codeforces.com/contest/349/problem/B
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- vector<int> v (10);
- string resultado ()
- {
- int num_base = 1;
- for (int i=1; i<10; i++)
- if (v[i] <= v[num_base])
- num_base = i;
- ///cout<<num_base<<endl;
- int cant_base = n/v[num_base];
- int cant_mejorables = cant_base;
- int sobra = n%v[num_base];
- if ( !cant_base )
- return "-1";
- string resp;
- for (int i=9; i>num_base; i--)
- {
- int costo = v[i] - v[num_base];
- if (sobra >= costo)
- {
- int mejoro = sobra/costo;
- for (int j=0; j<mejoro && j<cant_mejorables; j++)
- resp+= i+'0';
- cant_mejorables-=mejoro;
- sobra = sobra%costo;
- }
- }
- for (int i=0; i<cant_mejorables; i++)
- resp+= num_base+'0';
- return resp;
- }
- int main()
- {
- cin>>n;
- for (int i=1; i<10; i++)
- cin>>v[i];
- cout<<resultado();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement