結果

問題 No.156 キャンディー・ボックス
ユーザー IJMP320IJMP320
提出日時 2015-02-26 23:33:35
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 162,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-05 08:39:10
合計ジャッジ時間 2,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         rep(i,N) scanf("%d", &c[i]);
      |                  ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;
const int dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};
struct P{int x;int y;P(int X=0,int Y=0){x=X;y=Y;}};

int N, M;
vector<int> c;

int main() {
	cin >> N >> M;
	c.resize(N);
	rep(i,N) scanf("%d", &c[i]);
	sort(c.begin(),c.end());

	int sum = 0;
	rep(i,N) {
		sum += c[i];
		if(sum > M) {
			printf("%d\n",i);
			return 0;
		}
		else if(sum == M) {
			printf("%d\n", i+1);
			return 0;
		}
	}
	printf("%d\n",N);
	return 0;
}


0