2839번 - 설탕 배달
어디가 문제일까요 ㅠ 입력 예제 다 넣어보면 잘 나오는데 틀렸다네요 ㅠ
#include
using namespace std;
int main(void)
{
int i;
int j;
int result = 0;
int n;
int smallest = 999;
cin >> n;
if (n >= 3 && n <= 5000)
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (3 * i + 5 * j == n)
result = i + j;//4,6
if (smallest > result)//999 > 4
smallest = result;
}
else if (smallest < result)
continue;
cout << smallest;
if (smallest == 999)
cout << -1;
return 0;
입력 : 5000answer : 1000
output : -1
반례입니다
댓글을 작성하려면 로그인해야 합니다.
strive71 2년 전
어디가 문제일까요 ㅠ 입력 예제 다 넣어보면 잘 나오는데 틀렸다네요 ㅠ
#include
using namespace std;
int main(void)
{
int i;
int j;
int result = 0;
int n;
int smallest = 999;
cin >> n;
if (n >= 3 && n <= 5000)
{
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (3 * i + 5 * j == n)
{
result = i + j;//4,6
if (smallest > result)//999 > 4
{
smallest = result;
}
else if (smallest < result)
{
continue;
}
cout << smallest;
}
}
}
}
if (smallest == 999)
{
cout << -1;
}
return 0;
}