結果

問題 No.2806 Cornflake Man
ユーザー anonymously
提出日時 2024-07-12 22:54:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 776 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 202,972 KB
最終ジャッジ日時 2025-02-22 04:57:53
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int n;
	long long m;
	cin >> n >> m;
	vector<long long> A(n);
	for (int i = 0; i < n; i++)
		cin >> A[i];
	sort(A.begin(), A.end());
	vector<bool> B(n, false);
	B[0] = true;
	vector<long long> C;
	for (int i = 1; i < n; i++) {
		if (A[i] * (n - 1) < m) {
			cout << -1 << endl;
			return 0;
		}
		if (!B[i]) {
			if (A[i] * A[i] <= m) {
				long long k = A[i] * 2;
				for (int j = i + 1; j < n; j++) {
					if (A[j] > k) {
						cout << -1 << endl;
						return 0;
					}
					if (A[j] == k) {
						B[j] = true;
						k += A[i];
					}
				}
			}
			C.push_back(A[i]);
		}
	}
	cout << C.size() << endl;
	for (int i = 0; i < C.size(); i++) {
		if (i)
			cout << ' ';
		cout << C[i];
	}
	cout << endl;
	return 0;
}
0