結果

問題 No.5 数字のブロック
ユーザー te-shte-sh
提出日時 2016-11-20 01:57:44
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 359 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 106,280 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 05:08:59
合計ジャッジ時間 1,810 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  int l = readln.chomp.to!int;
  size_t n = readln.chomp.to!size_t;
  int[] wi = readln.split.to!(int[]);

  wi.sort();

  writeln(calc(l, wi));
}

size_t calc(int l, int[] wi)
{
  int a = 0;
  foreach (i, w; wi) {
    a += w;
    if (a > l) return i;
  }
  return wi.length;
}
0