結果
問題 | No.914 Omiyage |
ユーザー |
![]() |
提出日時 | 2019-10-25 21:36:59 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,221 bytes |
コンパイル時間 | 924 ms |
コンパイル使用メモリ | 113,424 KB |
実行使用メモリ | 28,520 KB |
最終ジャッジ日時 | 2024-09-24 16:26:03 |
合計ジャッジ時間 | 2,427 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Linq;using System.Collections.Generic;using System.IO;class MyClass{public static void Solve(){var input = Console.ReadLine().Split().Select(int.Parse).ToArray();var N = input[0];var M = input[1];var K = input[2];var sets = new HashSet<int>[N + 1];for (int i = 0; i < N + 1; i++){sets[i] = new HashSet<int>();}sets[0].Add(0);for (int i = 0; i < N; i++){var A = Console.ReadLine().Split().Select(int.Parse).ToArray();foreach (var item in sets[i]){for (int j = 0; j < M; j++){sets[i + 1].Add(item + A[j]);}}}var valid = sets[N].Where(x => x <= K);if (valid.Count() == 0){Console.WriteLine(-1);}else{Console.WriteLine(K - valid.Max());}}public static void Main(){var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };Console.SetOut(sw);Solve();Console.Out.Flush();}}