結果
| 問題 |
No.2424 Josouzai
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2023-08-18 22:14:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 416 bytes |
| コンパイル時間 | 2,235 ms |
| コンパイル使用メモリ | 196,144 KB |
| 最終ジャッジ日時 | 2025-02-16 10:13:17 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
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;
| ^~~
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;
| ^~~
ソースコード
#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 (tmp + a[i] <= k) {
tmp += a[i];
} else {
ans = i;
rem = k - tmp;
break;
}
}
cout << ans << ' ' << rem << endl;
}
Today03