Advertisement
osipyonok

Untitled

May 19th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define INF 1000010000
  4. #define nl '\n'
  5. #define pb push_back
  6. #define ppb pop_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define pii pair<int,int>
  11. #define pdd pair<double,double>
  12. #define all(c) (c).begin(), (c).end()
  13. #define SORT(c) sort(all(c))
  14. #define rep(i,n) for( int i = 0; i < n; ++i )
  15. #define repi(i,n) for( int i = 1 ; i <= n; ++i )
  16. #define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
  17. #define repf(j,i,n) for( int j = i ; j < n ; ++j )
  18. #define die(s) {std::cout << s << nl;}
  19. #define dier(s) {std::cout << s; return 0;}
  20. #define vi vector<int>
  21. typedef long long ll;
  22.  
  23. using namespace std;
  24.  
  25. inline bool solutable(int a , int b , int c){
  26.     while(c >= 0){
  27.         if(c % b == 0){
  28.             return 1;
  29.         }
  30.         c -= a;
  31.     }
  32.     return 0;
  33. }
  34.  
  35. int main() {
  36.     ios_base::sync_with_stdio(false);
  37.     cin.tie(NULL);
  38.     cout.precision(0);
  39.     int n;
  40.     int c1 , c2 , n1 , n2;
  41.     while(cin >> n){
  42.         if(!n) return 0;
  43.         cin >> c1 >> n1 >> c2 >> n2;
  44.         if(!(solutable(n1 , n2 , n))){ die("failed"); continue; }
  45.         ll ans1 = 0 , ans2 = 0;
  46.         while((n - ans2 * n2) % n1)
  47.             ++ans2;
  48.         ans1 = (n - n2 * ans2) / n1;       
  49.         ll ta1 = 0 , ta2 = 0;
  50.         while((n - ta1 * n1) % n2)
  51.             ++ta1;
  52.         ta2 = (n - n1 * ta1) / n2;     
  53.         if(ta1 * c1 + ta2 * c2 < ans1 * c1 + ans2 * c2){
  54.             ans1 = ta1;
  55.             ans2 = ta2;
  56.         }
  57.         cout << ans1 << " " << ans2 << nl;
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement