https://programmers.co.kr/learn/courses/30/lessons/42842
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int garo;
int sero;
void quad_eqn(double a, double b, double c)
{
double d, x, y;
d=b*b-4*a*c;
if(d>0)
{
x=(-b-sqrt(b*b-4*a*c))/2*a;
y=(-b+sqrt(b*b-4*a*c))/2*a;
garo = max(x, y);
sero = min(x, y);
}
else if(d==0)
{
x=b/(-2*a);
garo =x;
sero =x;
}
}
vector<int> solution(int brown, int yellow) {
vector<int> answer;
int a = 1;
int b = (-1)*((brown+4)/2);
int c = brown + yellow;
quad_eqn(a, b, c);
answer.push_back(garo);
answer.push_back(sero);
return answer;
}
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int brown, int red) {
int len = brown / 2 + 2;
int w = len - 3;
int h = 3;
while(w >= h){
if(w * h == (brown + red)) break;
w--;
h++;
}
return vector<int>{w, h};
}