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>
#include <cstdio>
using namespace std;
double q1,b,c1,c2,q2;

int main(){

  while(cin >> q1 , q1){
    cin >> b >> c1 >> c2 >> q2;
    int ach,bch;
    int mxa = 0,mxb = 0;
    int cost = 0;
    for( ach = 0 ; ach <= q2 ; ++ach ){
      cost = b - c1*ach;
      if(cost < 0)break;
      bch = cost/c2;
      if(mxa < ach && q1 <= ach + bch ){
	mxa = ach;
	mxb = bch;
      }
    }
    if(mxa < 1)cout << "NA" << endl;
    else cout << mxa << ' ' << mxb << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int main(){
      int a,b,c,d,e;
      while(cin>>a&&a){
            cin>>b>>c>>d>>e;
            int cnt1=min(e,b/c);
            int sum=b-cnt1*c;
            int cnt2=sum/d;
            sum-=cnt2*d;
            if(cnt1==0){
                  cout<<"NA"<<endl;
            }else if(cnt1+cnt2>=a){
                  cout<<cnt1<<" "<<cnt2<<endl;
            }else{
                  if(d>=c)cout<<"NA"<<endl;
                  else{
                        while(cnt2+cnt1<a&&cnt1>1){
                              sum+=c;cnt1--;
                              while(sum>=d){
                                    sum-=d;
                                    cnt2++;
                              }
                        }
                        if(cnt2+cnt1>=a&&cnt1>0)cout<<cnt1<<" "<<cnt2<<endl;
                        else cout<<"NA"<<endl;
                  }
            }
      }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	Int q1,b,c1,c2,q2;
	while(q1=in()){
		cin>>b>>c1>>c2>>q2;
		int i;
		for(i=b/c1;i>0;i--){
			if(b>=c1*i+c2*(q1-i)&&i<=q2)break;
		}
		if(i==0)cout<<"NA\n";
		else cout<<i<<" "<<(b-c1*i)/c2<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

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;
    int AizuCh = min(B/C1, Q2);
    int NCh = 0;
    for(;;) {
      if(AizuCh <= 0) { failed(); break; }
      NCh = (B - AizuCh*C1)/C2;
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      else AizuCh --;
    }
  }
   
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int want, money, c1, c2, meat;
  
  while(cin >> want){
    if(want == 0) break;
    cin >> money >> c1 >> c2 >> meat;
    
    int ans1 = money / c1;
    if(ans1 > meat) ans1 = meat;
    
    int budget = ans1 * c1; // テ、ツコツ暗ァツョツ療・ツ??」ツ?ァテ」ツ?ァテ」ツ?催」ツつ凝」ツ??」ツ?妥・ツ慊ーテゥツカツ湘」ツつ津ィツイツキテ」ツ?」テ」ツ?淌・ツ?、テヲツョツオ
    int ans2 = 0;
    int sale = money - budget;
    sale = max(0, sale);
    while(1){
      if(ans1 + ans2 >= want) break;
      if(ans1 == 0) break;
      int buy_normal = sale / c2;
      ans2 += buy_normal; //テ・ツ慊ーテゥツカツ湘」ツつ津・ツ」ツイテ」ツ?」テ」ツ?ヲテ」ツ?ァテ」ツ?催」ツ?淌」ツ?甘ゥツ?妥」ツ?ァテ」ツ?ァテ」ツ?催」ツつ凝」ツ??」ツ?妥ゥツカツ湘ィツつ嘉」ツつ津ィツイツキテ」ツ??テ・ツ?凝ヲツ閉ーテッツシツ?
      if(ans1 + ans2 >= want) break;

      ans1--, budget -= c1; // テ、ツクツ?」ツ?、テ・ツ」ツイテ」ツつ?
      sale += c1; // テ・ツ」ツイテ」ツ?」テ」ツ?ヲティツイツーテ」ツ?」テ」ツ?淌」ツ?甘ゥツ??
      
      sale -= buy_normal * c2;     
      budget += ans2 * c2;

    }
    if(ans1 == 0) cout << "NA" << endl;    
    else cout << ans1 << ' ' << ans2 << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

int L, B, AC, NC, U;

int main(){
    while(scanf("%d%d%d%d%d",
                &L, &B, &AC, &NC, &U) != EOF && L){
        int lb = 0, ub = U;
        while(lb <= ub){
            int m = (lb + ub) / 2;
            if(B - AC * m >= 0 && m + (B - AC * m) / NC >= L){
                lb = m+1;
            }else{
                ub = m-1;
            }
        }
        if(lb > 1){
            printf("%d %d\n", lb-1, (B - AC * lb + AC) / NC);
        }else{
            puts("NA");
        }
    }
    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;
    
    assert(Q2 >= 1);
    
    /*
    if(B/C1 == 0) {
      failed(); continue;
    }
    */
    
    int AizuCh = min(B/C1, Q2);
    if(AizuCh <= 0) { failed(); continue; }
    int NCh = 0;
    for(;;) {
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      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 q1, b, c1, c2, q2;

int check (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 >> b >> c1 >> c2 >> q2 && q1 ){

		int x, y;
		int l = 0;
		int r = q2;

		while (l <= r ){
			x = (l + r )/2;
			if ((y = check(x ) ) == - 1 ){
				r = x - 1;
			}else{
				l = x + 1;
			} // end if
		} // end while
		x = min (l, r );
		y = check(x );

		if (x <= 0 ){
			cout << "NA" << endl;
		}else{
			cout << x << ' ' << y << endl;
		} // end if
	} // end while

	return 0;
}