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 <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	long long int must_amount,budget,price_aizu,price_normal,aizu_limit,left,right,max_aizu,max_normal,m,tmp_normal;

	while(true){
		scanf("%lld",&must_amount);
		if(must_amount == 0)break;

		scanf("%lld %lld %lld %lld",&budget,&price_aizu,&price_normal,&aizu_limit);

		max_aizu = 0;

		left = 1,right = aizu_limit;
		m = (left + right)/2;

		while(left <= right){
			if(price_aizu*m > budget){
				right = m - 1;
				m = (left + right)/2;
			}else{
				tmp_normal = (budget - price_aizu*m)/price_normal;
				if(tmp_normal + m >= must_amount){
					max_aizu = m;
					max_normal = tmp_normal;
					left = m + 1;
					m = (left + right)/2;
				}else{
					if(price_aizu < price_normal){
						left = m + 1;
						m = (left + right)/2;
					}else{
						right = m - 1;
						m = (left + right)/2;
					}
				}
			}
		}

		if(max_aizu == 0)printf("NA\n");
		else{
			printf("%lld %lld\n",max_aizu,max_normal);
		}
	}
	return 0;
}

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

int main() {
  int q1, b, c1, c2, q2, n1, n2;

  while (1) { 
    cin >> q1;
    if (!q1) break;

    cin >> b >> c1 >> c2 >> q2;
    if (c1 > c2) {
      n1 = (b - c2 * q1) / (c1 - c2);
      if (n1 > q1) {
        n1 = b / c1;
      }
    } else {
      n1 = b / c1;
    }
    if (n1 > q2) {
      n1 = q2;
    }
    n2 = (b - c1 * n1) / c2;

    if (n1 <= 0) {
      cout << "NA" << endl;
    } else {
      cout << n1 << " " << n2 << endl;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int line;
    while(cin>>line,line){
        int have,aiz_m,usu_m,aiz_max;
        cin>>have>>aiz_m>>usu_m>>aiz_max;
        bool kawa=0;
        for(int i=min(aiz_max,have/aiz_m);i>0&&!kawa;i--){
            for(int now=have-i*aiz_m,j=now/usu_m;j>-1&&!kawa;j--){
                if(have-j*usu_m>=0&&i+j>=line){
                    cout<<i<<" "<<j<<endl;
                    kawa=1;
                }
            }
        }
        if(!kawa)cout<<"NA\n";
    }
}

C++: // 2011/08/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int q1;
		cin >> q1;
		if(q1==0)
			break;

		int b, c1, c2, q2;
		cin >> b >> c1 >> c2 >> q2;

		int A;
		if(c1==c2&&b/c1<q1){
			cout << "NA" << endl;
			continue;
		}
		else if(c1==c2){
			A = b/c1;
		}
		else{
			A = (b-c2*q1)/(c1-c2);
		}
		if(A<=0){
			cout << "NA" << endl;
			continue;
		}
		if(A>q2)
			A = q2;

		int B = (b-c1*A)/c2;
		if(B<0){
			A = b/c1;
			B = (b-c1*A)/c2;
		}

		cout << A << ' ' << B << endl;
	}

	return 0;
}

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

int main()
{
    int q1, b, c1, c2, q2;

    while( cin >> q1 )
    {
        if( !q1 )
            break;
        
        cin >> b >> c1 >> c2 >> q2;

        bool judge = false;
        for( int i = q2; i >= 1; i-- )
        {
            int sum = b - c1 * i;
            if( sum < 0 )
                continue;
            else if( sum / c2 + i >= q1 )
            {
                cout << i << " " << sum / c2 << endl;
                judge = true;
                break;
            }
        }

        if( !judge )
            cout << "NA" << endl;
    }

    return 0;
}

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

#define INF (1 << 21)

using namespace std;

int N;

int check[100000];

queue<string> que, que_next;

int index(string str){
	
	int ref = 0;
	
	for(int i = 0; i < N; i++){
		ref *= 3;
		ref += str[i] - '0';
	}
	
	return ref;
}

int main(){
	
	while(true){
		
		int b, c1, c2, q1, q2;
		
		cin >> q1;
		
		if(q1 == 0){
			break;
		}
		
		cin >> b >> c1 >> c2 >> q2;
		
		int ans1, ans2;
		
		int hoge = 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;


typedef struct struct_input
{
	//欲しい肉の量
	int niku;
	//予算
	int yosan;
	//地鶏の値段
	int didori_nedan;
	//普通の
	int normal_tori;
	//地鶏を最大で買える数
	int didori_max;
}S_input;


S_input s_input;




int main(void)
{
	while (true)
	{
		int ans1 = 0 , ans2 = 0;

		cin >> s_input.niku;

		if (s_input.niku == 0)	{	return 0;	}

		cin >> s_input.yosan >> s_input.didori_nedan >> s_input.normal_tori >> s_input.didori_max;
	
		//地鶏の最大
		for (int i = 0; i < s_input.didori_max; i++)
		{
			//金の少ない多い
			if (s_input.yosan < s_input.didori_nedan)
			{
				break;
			}
			s_input.yosan -= s_input.didori_nedan;
			ans1++;
		}

		//残りの金で鶏肉を買う
		while (s_input.yosan > s_input.normal_tori)
		{
			ans2++;
			s_input.yosan -= s_input.normal_tori;
		}

		if (ans1 == 0)
		{
			cout << "NA" << endl;
			continue;
		}
		if (ans1 + ans2 >= s_input.niku)
		{
			cout << ans1 << " " << ans2 << endl;
			continue;
		}

		//2つの肉の差
		int sa = s_input.didori_nedan - s_input.normal_tori;
		while (ans1 > 0)
		{
			ans1--;
			ans2++;
			s_input.yosan += sa;

			while (s_input.yosan >= s_input.normal_tori)
			{
				ans2++;
				s_input.yosan -= s_input.normal_tori;
			}

			if (ans1 + ans2 >= s_input.niku)
			{
				break;
			}
		}
		

		if (ans1 + ans2 >= s_input.niku && ans1 != 0)
		{
			cout << ans1 << " " << ans2 << endl;
			continue;
		}
		cout << "NA" << endl;
	
	}

	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<queue>
using namespace std;
int main(){
    int q1,b,c1,c2,q2;
    while(cin>>q1,q1){
        cin>>b>>c1>>c2>>q2;
        int x,y;
        x=min(b/c1,q2);

        for(int i=x;i>=0;i--){
            if(i==0)cout<<"NA"<<endl;
            else if(i+(b-i*c1)/c2>=q1){
                cout<<i<<" "<<(b-i*c1)/c2<<endl;
                break;
            }
        }
    }
    return 0;
}

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

int main() {
 double k;	
 int i,hi,lo,m,b,q1,q2,c1,c2;
 while (cin >> q1 && q1!=0) {
	 cin >> b >> c1 >> c2 >> q2;
	 hi=q2+1; lo=0; 
	 for (i=0;i<30;i++) {
		 m=(hi+lo)/2;
		 k=(double)(b-c1*m)/c2;
		 if (k>=0 && (m+k)>=q1) lo=m; else hi=m;
	 }
	 if (m==0) cout << "NA" << endl; else cout << m  << ' ' << (b-c1*m)/c2 << endl;
 }    
  return 0;
}