結果

問題 No.5 数字のブロック
ユーザー pe
提出日時 2017-06-10 14:23:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 413 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 22,656 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-24 15:34:45
合計ジャッジ時間 1,912 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d%d",&l,&n);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:7:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |                 scanf("%d",&w[i]);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
int l,n,w[10000],p,s,y,m,i;
int main()
{
	scanf("%d%d",&l,&n);
	for(i=0;i<n;i++){
		scanf("%d",&w[i]);
	}
	do{s=0;
		for(i=0;i<n-p;i++){
			if(w[i]>w[i+1]){
				w[i]^=w[i+1];
				w[i+1]^=w[i];
				w[i]^=w[i+1];
				s=1;
			}
		}
		p++;
		//puts("石倉");
	}while(s!=0);
	for(i=0;i<n;i++){
		if((y+w[i])>l){
			break;
		}
		if(w[i]>0){
			y+=w[i];
			m++;
		}
	}
	printf("%d\n",m);
	return 0;	
}
0