結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー ふう
提出日時 2015-02-26 23:27:40
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 911 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 592 ms
コンパイル使用メモリ 107,144 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-26 15:41:27
合計ジャッジ時間 1,465 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:65:17: warning: 'res' may be used uninitialized [-Wmaybe-uninitialized]
   65 |         cout << res << endl;
      |                 ^~~
main.cpp:43:13: note: 'res' was declared here
   43 |         int res;
      |             ^~~

ソースコード

diff #
raw source code

/* nQueen問題 */

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#include <functional>

#define SIZE 1005
#define INF 100000000
#define ll long long
#define FD(d) fixed << setprecision(d)
#define MOD 1000000007
     
using namespace std;
 
#define ll long long
 
typedef pair<int, int> Pa;


#define SUCCESS 1
#define FAIL    0

#define FREE		1
#define NOT_FREE    0

int main()
{
	int n, m;
	int c[SIZE];
	int res;

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}

	sort(c, c + n);
	
	for (int i = 0; i < n; i++) {
		m -= c[i];
		if (m < 0) {
			res = i;
			break;
		}
		if(m == 0) {
			res = i + 1;
		}
	}


	cout << res << endl;

	return (0);
}
0