結果

問題 No.914 Omiyage
ユーザー suzusuzu
提出日時 2023-06-09 11:47:02
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,370 bytes
コンパイル時間 4,416 ms
コンパイル使用メモリ 104,724 KB
実行使用メモリ 23,996 KB
最終ジャッジ日時 2023-08-30 07:13:46
合計ジャッジ時間 7,151 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 66 ms
19,900 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 AC 66 ms
21,868 KB
testcase_08 AC 66 ms
21,852 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 66 ms
21,892 KB
testcase_14 AC 65 ms
19,972 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 67 ms
21,744 KB
testcase_19 WA -
testcase_20 AC 66 ms
21,824 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;

namespace yukicoder
{
	class pg
	{
		
		static void Main(string[] args)
		{
			var line = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
			int N = line[0];
			int M = line[1];
			int K = line[2];
			
			var nations = new List<int>[N];
			var takeGiftList = Enumerable.Repeat<int>(1,N).ToArray();
			
			int iniTotal = 0;
			
			for(int i = 0;i < N;i++)
			{
				var gifts = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).OrderBy(c => c).ToList();
				nations[i] = gifts;
				iniTotal += gifts[0];
			}
			
			if(iniTotal > K)Console.WriteLine(-1);
			
			int total = iniTotal;
			int oldTotal;
			
			while(true)
			{
				int minMoney = int.MaxValue;
				int minNation = -1;
				bool SerchFlag = false;
				for(int q = 0;q < N;q++)
				{
					if(takeGiftList[q] >= N)continue;
					
					int a = nations[q][takeGiftList[q]];
					if(a < minMoney)
					{
						SerchFlag = true;
						minNation = q;
						minMoney = a;
					}
				}
				
				if(!SerchFlag)
				{
					Console.WriteLine(K - total);
					return;
				}
				
				oldTotal = total;
				int b = takeGiftList[minNation];
				int c = nations[minNation][b] - nations[minNation][b - 1];
				
				if(total + c > K)
				{
					Console.WriteLine(K - total);
					return;
				}
				total += c;
			}
			
			
			
		}
	}
}	
0