코딩테스트

06/02 백준 코딩테스트 2839 설탕 배달

박준희 2021. 6. 2. 01:26

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int tmp = n / 5;
            int count5kg;
            int count3kg;
            bool bol = true;
            for (int i = tmp; i >= 0; i--)
            {
                count5kg = i;
                int a = n - (5 * count5kg);
                count3kg = a / 3;
                int b = count5kg * 5 + count3kg * 3;
                if (b == n)
                {
                    Console.WriteLine(count3kg + count5kg);
                    bol = false;
                    break;
                }

            }
            if (bol)
            {
                Console.WriteLine(-1);
            }
        }
    }
}

 

문제 푸는데 30분 정도 걸렸다.