Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		if buf[0] == "0" {
			break
		}
		q1, _ := strconv.Atoi(buf[0]) // 買うべき鶏肉の量の下限(g)
		b, _ := strconv.Atoi(buf[1])  // 予算
		c1, _ := strconv.Atoi(buf[2]) // 会津地鶏の値段(/100g)
		c2, _ := strconv.Atoi(buf[3]) // 普通の鶏肉の値段(/100g)
		q2, _ := strconv.Atoi(buf[4]) // 会津地鶏の買える量の上限(g)
		maxAizuChiken := min(b/c1, q2)
		if maxAizuChiken <= 0 {
			fmt.Println("NA")
			continue
		}
		if c2 >= c1 {
			maxNormalChiken := (b - maxAizuChiken*c1) / c2
			if maxAizuChiken+maxNormalChiken < q1 { // 買い切ったけども必要な鶏肉の下限に達しなかった
				fmt.Println("NA")
			} else {
				fmt.Println(maxAizuChiken, maxNormalChiken)
			}
			continue
		}
		if (b-c1)/c2+1 < q1 { // 会津地鶏を1単位+普通の鶏肉を予算目一杯買ったが買うべき下限を超えなかった
			fmt.Println("NA")
			continue
		}
		// 二分探索
		low, high := 0, maxAizuChiken+1
		for high-low > 1 {
			mid := (low + high) / 2
			if check(mid, b, c1, c2, q1) {
				low = mid
			} else {
				high = mid
			}
		}
		fmt.Println(low, (b-low*c1)/c2)
	}
}

func check(mid, b, c1, c2, q1 int) bool {
	if mid+(b-mid*c1)/c2 < q1 {
		return false
	}
	return true
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

C++: #include <iostream>
using namespace std;

/*
  x := 会津地鶏の購入量, y := 普通の鶏肉の購入量 として
  q1 <= x + y
  0 < x <= q2
  0 <= y
  c1 * x + c2 * y <= b 
  を満たす(x,y)の中で x が最大のものを求める, 複数あるときはその中で y が最大のもの
  
  x == 0 のときは "NA" を出力する
*/
int q1, b, c1, c2, q2;

// 上記の式を満たさない (x,y) の組のときは -1 を, そうでないときは y を返す.
int f(int x){
	int y = (b - c1 * x) / c2;
	if( x+y < q1 ) return -1;
	if( y < 0 ) return -1;
	if( b - c1 * x < 0 ) return -1;
	return y;
}

int main(){	
	
	while( cin >> q1, q1 ){
		cin >> b >> c1 >> c2 >> q2;
		
		// x について二分探索
		int low=0, high=q2;
		while( high - low > 1 ){
			int mid = (low + high) / 2;
			if( f(mid) == -1 ){
				high = mid;
			}else{
				low = mid;
			}
		}
		int x, y;
		x = (f(high) == -1)? low : high ;
		y = f(x);
		if( x == 0 ){
			cout << "NA" << endl;
		}else{
			cout << x << " " << y << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int q1, b, c1, c2, q2;
P ans;

int main(){
	while (cin >> q1&&q1){
		cin >> b >> c1 >> c2 >> q2;
		ans = P(-1, -1);
		if (c2 < c1){
			FOR(i, 1, q2 + 1){
				if (q1 - i >= 0){
					if (i*c1 + (q1 - i)*c2 <= b){
						int co = (b - i*c1) / c2;
						if (ans.first < i&&co >= 0){
							ans = P(i, co);
						}
					}
				}
				else{
					if (i*c1 <= b){
						ans = P(i, 0);
					}
				}
			}
			if (ans.first >= 0 && ans.second >= 0)cout << ans.first << " " << ans.second << endl;
			else cout << "NA" << endl;
		}
		else{
			ans = P(0, 0);
			REP(i, q2){
				if (b - c2 > 0){
					b -= c2;
					ans.first++;
				}
			}
			while (b - c1 > 0){
				b -= c1;
				ans.second++;
			}
			if (ans.first + ans.second <= q1)cout << "NA" << endl;
			else cout << ans.first << " " << ans.second << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int a[10];

int main(){
	
	while(true){
		
		int b, c1, c2, q1, q2;
		
		cin >> q1;
		
		if(q1 == 0){
			break;
		}
		
		cin >> b >> c1 >> c2 >> q2;
		
		int ans1, ans2;
		
		a[-1] = 0;
		if(c1 <= c2){
			ans1 = min(b / c1, q2);
			ans2 = (b - c1 * ans1) / c2;
		}else if(q1 * c1 > b){
			ans1 = min((b - q1 * c2) / (c1 - c2), q2);
			ans2 = (b - c1 * ans1) / c2;
		}else{
			ans1 = min(b / c1, q2);
			ans2 = (b - c1 * ans1) / c2;
		}
		
		
		if(ans1 < 1 || ans2 < 0){
			cout << "NA" << endl;
		}else{
			cout << ans1 << " " << ans2 << endl;
		}
		
		//cout << ans1 << " " << ans2 << endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int q1,b,c1,c2,q2;
  cin >> q1;
  while(q1!=0){
    cin >> b >> c1 >> c2 >> q2;
    int x1=0,x2=0,m=min(c1,c2);
    bool f=false;
    //cout << b-min(c1,c2)*q1 << endl;
    if(b<m*q1) f=true;
    
    int s=c1-c2,sum=0;
    sum=q1*m;
    while(b-sum>=s*(x1+1)&&x1<q2&&b>=c1*(x1+1)) {
      x1++; 
      //cout << b-sum<<":"<<s*x1<<endl;
      //cout << x1<<":"<<c1*x1<<endl;
    }
    //while(b>=c1*(x1+1)&&x1<q2) x1++;
    //while(b>=c1*x1+c2*(x2+1)) x2++;
    
    if(x1==0) f=true;
    x2=q1-x1;
    while(b>=c1*x1+c2*(x2+1)) x2++;
    if(f) cout << "NA" << endl;
    else cout << x1 << " " << x2 << endl;
    cin >> q1;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1 >> B >> C1 >> C2 >> Q2) {
    if(Q1 == 0) break;
    
    if(B/C1 == 0) {
      failed(); continue;
    }
    
    int AizuCh = min(B/C1, Q2);
    int NCh = 0;
    for(;;) {
      
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      
      else if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh += (B - NCh*C2 - AizuCh*C1)/C2;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int count=0,count2=0,b,c1,d=0,i,j,q1,c2,q2,y=0;
  while(1){
    j=0;
    y=0;
    count=0;
    count2=0;
    cin >> q1;
    if(q1==0){
      break;
    }
    cin >> b >> c1 >> c2 >> q2;
    if(b<c1){
      cout << "NA" <<endl;
      continue;
    }
    while(b>=c1){
      b=b-c1;
      count++;
      if(count >= q2){
	break;
      }
    }
    if(b<c2 && count<q1){
      cout << "NA" <<endl;
      continue;
    }
    if(b>=c2){
      while(b>=c2){
	b=b-c2;
	count2++;
      }
    }
    if(count+count2<q1){
      while(1){
	d=0;
	count--;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	b=b+c1;
	while(c1>=c2*d){
	  count2++;
	  b=b-c2;
	  d++;
	  if(count+count2>=q1){
	    y=1;
	    break;
	  }
	}
	if(y==1){
	  break;
	}
      }
    }
    if(j!=1){
      cout << count << " " << count2 <<endl;
    }
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
main(){
  while(1){
    int q1;
    scanf("%lld",&q1);
    if(!q1) break;
    ll b,c1,c2,q2;
    scanf("%lld %lld %lld %lld",&b,&c1,&c2,&q2);
    ll res1=0,res2=0;

    if(c1<=c2){
      if(b >= c1*q2){
	b-=c1*q2;
	res1 = q2;
      }else{
	b-=(b/c1)*c1;
	res1 = b/c1;
      }
      res2 = b/c2;
      if(res1 + res2 < q1 || res1==0) puts("NA");
      else printf("%lld %lld\n",res1,res2);
      continue;
    }

    ll st=1,ed=q2;
    while(st<=ed){
      ll h=(st+ed)/2;
      ll x=b;
      x -= c1*h;
      if(x < 0){
	ed = h-1;
	continue;
      }
      ll t2 = (x/c2);
      x -= t2*c2;
      if( x>=0 && h+t2>=q1 ){
	res1 = h;
	res2 = t2;
	st = h+1;
      }else{
	ed = h-1;
      }
    }
    if(!res1 && !res2) puts("NA");
    else printf("%lld %lld\n",res1,res2);
  }
}