
규칙만 찾으면 쉬운 문제
16 5 => 3 3 3 3 4
17 5 => 3 3 3 4 4
18 5 => 3 3 4 4 4
s를 n으로 나눈 값 x가 중심값
나머지 값 c가 x+1 값의 개수
n이 s 보다 크면 {-1} 값을 returnx는 n-c개, x+1는 c개 반복해서 벡터에 넣어준다.#include <string>
#include <vector>
using namespace std;
vector<int> solution(int n, int s) {
vector<int> answer;
int x = s/n;
int c = s%n;
if(n>s) return {-1};
for(int i=0;i<n-c;i++)
{
answer.push_back(x);
}
for(int i=0;i<c;i++)
{
answer.push_back(x+1);
}
return answer;
}
소스 코드가 너무 좋아서 퍼가요💕