結果

問題 No.5 数字のブロック
ユーザー streingmuststreingmust
提出日時 2017-04-09 10:57:11
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,066 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 61,480 KB
実行使用メモリ 814,828 KB
最終ジャッジ日時 2023-09-25 01:17:15
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int med3(int x, int y, int z){
	if(x<y){
		if(y<z){
			return y;
		}
		else if (z < x){
			return x;
		}
		else{
			return z;
		}
	}
	else{
		if(x<z){
			return x;
		}
		else if(z < y){
			return y;
		}
		else {
			return z;
		}
	}
}
		

void quicksort(std::vector<int> a,int left, int right){
	if(left < right){
		int i = left;
		int j = right;
		int tmp = left;
		int pivot = med3(a[i], a[i + (j - i)/2], a[j]);
		while(true){
			while(a[i] < pivot){
				i++;
			}
			while(pivot<a[j]){
				j--;
			}
			if(i > j) break;
			tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
			i++;
			j--;
		}
		quicksort(a, left, i - 1);
		quicksort(a, j + 1, right);
	}
}


int main(void){
	int W;
	int N;
	std::cin >> W;
	std::cin >> N;
	std::vector<int> w;
   int tt = 0;
	for(int i=0; i<N; i++){
		std::cin >> tt;
w.push_back (tt);
	}
	quicksort(w, 0, N - 1);
	int sum=0;
	int i = 0;
	while(true){
		sum += w[i];
		if(sum > W){
			std::cout << i;
			break;
		}
		i++;
		if(i == N){
			std::cout << i << std::endl;
			break;
		}
	}
	return 0;
}
0