0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#でAtCoder Beginners Selection ABC085C Otoshidama

Posted at

自分が書いたコード

using System;
using System.Linq;
 
class Program
{
    static void Main(string[] args)
    {
		int[] input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int N = input[0];
		int Y = input[1] / 1000;
		for (int i = 0; i <= N; i++)
		{
			for (int j = 0; j <= N - i; j++)
			{
				int k = N - (i + j);
				if (10 * i + 5 * j + k == Y)
				{
					Console.WriteLine($"{i} {j} {k}");
					return;
				}
			}
		}
		Console.WriteLine("-1 -1 -1");
    }
}

最初に提出したときは x, yがそれぞれ決まれば z が勝手に定まることをすっかり忘れて?しまって、なぜか3重ループを書いていました、、、

問題文的に全体を1000で割ってしまって問題なかったので1000で割った。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?