結果

問題 No.2424 Josouzai
ユーザー Today03Today03
提出日時 2023-08-18 22:15:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 426 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 204,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 04:25:34
合計ジャッジ時間 5,165 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 27 ms
5,376 KB
testcase_05 AC 96 ms
5,376 KB
testcase_06 AC 87 ms
5,376 KB
testcase_07 AC 87 ms
5,376 KB
testcase_08 AC 95 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 24 ms
5,376 KB
testcase_11 AC 64 ms
5,376 KB
testcase_12 AC 48 ms
5,376 KB
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 52 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 81 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 27 ms
5,376 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 86 ms
5,376 KB
testcase_21 AC 62 ms
5,376 KB
testcase_22 AC 29 ms
5,376 KB
testcase_23 AC 35 ms
5,376 KB
testcase_24 AC 16 ms
5,376 KB
testcase_25 AC 88 ms
5,376 KB
testcase_26 AC 62 ms
5,376 KB
testcase_27 AC 90 ms
5,376 KB
testcase_28 AC 79 ms
5,376 KB
testcase_29 AC 72 ms
5,376 KB
testcase_30 AC 19 ms
5,376 KB
testcase_31 AC 41 ms
5,376 KB
testcase_32 AC 89 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:23:25: warning: 'rem' may be used uninitialized [-Wmaybe-uninitialized]
   23 |   cout << ans << ' ' << rem << endl;
      |                         ^~~
main.cpp:13:12: note: 'rem' was declared here
   13 |   int ans, rem;
      |            ^~~
main.cpp:23:18: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   23 |   cout << ans << ' ' << rem << endl;
      |                  ^~~
main.cpp:13:7: note: 'ans' was declared here
   13 |   int ans, rem;
      |       ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long tmp = 0;
  int ans, rem;
  for (int i = 0; i <= n; i++) {
    if (i < n && tmp + a[i] <= k) {
      tmp += a[i];
    } else {
      ans = i;
      rem = k - tmp;
      break;
    }
  }
  cout << ans << ' ' << rem << endl;
}
0