結果

問題 No.156 キャンディー・ボックス
ユーザー FVRChan
提出日時 2017-09-29 09:28:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 67,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 16:05:44
合計ジャッジ時間 1,511 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int sum=0,counter=0,n,m;scanf("%d%d",&n,&m);
      |                                 ~~~~~^~~~~~~~~~~~~~
main.cpp:11:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         for(int i=0;i<n;i++)scanf("%d",&are[i]);
      |                             ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<cstdio>
#include<utility>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int sum=0,counter=0,n,m;scanf("%d%d",&n,&m);
	int *are=new int[n];
	for(int i=0;i<n;i++)scanf("%d",&are[i]);
	sort(are,are+n);
	for(int i=0;i<n;i++){
		sum+=are[i];
		if(sum>m){
			break;
		}else if(sum==m){
			counter++;
			break;
		}counter++;
	}cout<<counter<<endl;
}
0