Language: C++

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0120 : Patisserie **/
const int MAX_N = 12;

double W;
vector<double> size;
int dp[1<<MAX_N][MAX_N];
int N;

int sig(double a, double b) {
	if(a < b - EPS) return -1;
	if(a > b + EPS) return +1;
	return 0;
}

bool rec(int S, int v, double w)
{
	//printf("(S, v, w) = (%d, %d, %.2f)\n", S, v, w);
	
	if (dp[S][v]>=0)
		return dp[S][v];
	
	if (S==(1<<N)-1) {
		printf("%.2f %.2f\n", W, w);
		return dp[S][v] = (sig(W, w)!=-1);
	}
	
	bool res=false;
	rep(u, N) {
		if (!(S>>u&1)) {
			double nw = w - size[v] + size[u] + sqrt((size[u]+size[v])*(size[u]+size[v]) - (size[u]-size[v])*(size[u]-size[v]));
			res |= rec(S|1<<u, u, nw);
		}
	}
	
	return dp[S][v] = res;
}

int main()
{
	string in;
	while (getline(cin, in)) {
		size.clear();
		
		stringstream ss(in);
		ss>>W;
		double d;
		while (ss>>d) {
			size.push_back(d);
		};
		N=(int)size.size();
		
		memset(dp, -1, sizeof(dp));
			
		bool ans=false;
		rep(i, N) {
			ans |= rec(1<<i, i, 2*size[i]);
		}
		
		cout << (ans?"OK":"NA") << endl;
	}
}

Compiler output:
a.cc:7:9: error: 'pair' does not name a type
    7 | typedef pair<int, int> P;
      |         ^~~~
a.cc:13:1: error: 'vector' does not name a type
   13 | vector<double> size;
      | ^~~~~~
a.cc: In function 'bool rec(int, int, double)':
a.cc:31:17: error: 'printf' was not declared in this scope
   31 |                 printf("%.2f %.2f\n", W, w);
      |                 ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | const int INF = 100000000;
a.cc:36:13: error: 'u' was not declared in this scope
   36 |         rep(u, N) {
      |             ^
a.cc:36:9: error: 'rep' was not declared in this scope; did you mean 'res'?
   36 |         rep(u, N) {
      |         ^~~
      |         res
a.cc: In function 'int main()':
a.cc:48:9: error: 'string' was not declared in this scope
   48 |         string in;
      |         ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | const int INF = 100000000;
a.cc:49:24: error: 'cin' was not declared in this scope
   49 |         while (getline(cin, in)) {
      |                        ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | const int INF = 100000000;
a.cc:49:29: error: 'in' was not declared in this scope; did you mean 'int'?
   49 |         while (getline(cin, in)) {
      |                             ^~
      |                             int
a.cc:49:16: error: 'getline' was not declared in this scope
   49 |         while (getline(cin, in)) {
      |                ^~~~~~~
a.cc:50:17: error: 'size' was not declared in this scope
   50 |                 size.clear();
      |                 ^~~~
a.cc:52:17: error: 'stringstream' was not declared in this scope
   52 |                 stringstream ss(in);
      |                 ^~~~~~~~~~~~
a.cc:1:1: note: 'std::stringstream' is defined in header '<sstream>'; this is probably fixable by adding '#include <sstream>'
  +++ |+#include <sstream>
    1 | const int INF = 100000000;
a.cc:53:17: error: 'ss' was not declared in this scope
   53 |                 ss>>W;
      |                 ^~
a.cc:60:17: error: 'memset' was not declared in this scope
   60 |                 memset(dp, -1, sizeof(dp));
      |                 ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | const int INF = 100000000;
a.cc:63:21: error: 'i' was not declared in this scope
   63 |                 rep(i, N) {
      |                     ^
a.cc:63:17: error: 'rep' was not declared in this scope; did you mean 'rec'?
   63 |                 rep(i, N) {
      |                 ^~~
      |                 rec
a.cc:67:17: error: 'cout' was not declared in this scope
   67 |                 cout << (ans?"OK":"NA") << endl;
      |                 ^~~~
a.cc:67:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:67:44: error: 'endl' was not declared in this scope
   67 |                 cout << (ans?"OK":"NA") << endl;
      |                                            ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | const int INF = 100000000;