Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define INF 1000010000
- #define nl '\n'
- #define pb push_back
- #define ppb pop_back
- #define mp make_pair
- #define fi first
- #define se second
- #define pii pair<int,int>
- #define pdd pair<double,double>
- #define all(c) (c).begin(), (c).end()
- #define SORT(c) sort(all(c))
- #define rep(i,n) for( int i = 0; i < n; ++i )
- #define repi(i,n) for( int i = 1 ; i <= n; ++i )
- #define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
- #define repf(j,i,n) for( int j = i ; j < n ; ++j )
- #define die(s) {std::cout << s << nl;}
- #define dier(s) {std::cout << s; return 0;}
- #define vi vector<int>
- typedef long long ll;
- using namespace std;
- inline bool solutable(int a , int b , int c){
- while(c >= 0){
- if(c % b == 0){
- return 1;
- }
- c -= a;
- }
- return 0;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.precision(0);
- int n;
- int c1 , c2 , n1 , n2;
- while(cin >> n){
- if(!n) return 0;
- cin >> c1 >> n1 >> c2 >> n2;
- if(!(solutable(n1 , n2 , n))){ die("failed"); continue; }
- ll ans1 = 0 , ans2 = 0;
- while((n - ans2 * n2) % n1)
- ++ans2;
- ans1 = (n - n2 * ans2) / n1;
- ll ta1 = 0 , ta2 = 0;
- while((n - ta1 * n1) % n2)
- ++ta1;
- ta2 = (n - n1 * ta1) / n2;
- if(ta1 * c1 + ta2 * c2 < ans1 * c1 + ans2 * c2){
- ans1 = ta1;
- ans2 = ta2;
- }
- cout << ans1 << " " << ans2 << nl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement