結果

問題 No.2424 Josouzai
ユーザー Today03Today03
提出日時 2023-08-18 22:15:51
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 426 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 204,796 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 07:48:13
合計ジャッジ時間 5,126 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
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