結果

問題 No.5 数字のブロック
ユーザー たつおたつお
提出日時 2023-09-26 10:57:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 479 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 73,212 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 05:39:44
合計ジャッジ時間 1,554 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(void){
//input
	int L,N;
	cin >> L;
	cin >> N;
	
	int box[N];
	for(int i=0;i<N;i++){
		cin >> box[i];
	}
//calc
	vector<int> boxes;
	for(int i=0;i<N;i++){
		boxes.push_back(box[i]);
		int sum = accumulate(boxes.begin(),boxes.end(),0);
		if(sum > L){
			boxes.erase(max_element(boxes.begin(),boxes.end()));
		}
	}
	int cnt = boxes.size();
//output
	cout << cnt << endl;
}
0