結果

問題 No.59 鉄道の旅
ユーザー dora_marutadora_maruta
提出日時 2014-11-11 17:10:10
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 886 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 60,180 KB
実行使用メモリ 11,696 KB
最終ジャッジ日時 2023-08-26 05:32:45
合計ジャッジ時間 6,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

int contena[1000001];

int main(){
	//std::vector<int> contena;
	int n, k;
	std::cin >> n >> k;
	int m = 0;
	int d = 0;
	for (int i = 0; i < n; ++i){
		int w;
		std::cin >> w;
		m = std::max(m, w);
		if (w > 0){
			int cnt = 0;
			for (int j = m; j >= w; --j){
				if (contena[j] != 0)cnt+=contena[j];
			}
			if (cnt < k){
				contena[w]++;
				//std::cout << w << "gain" << std::endl;
			}
		}
		else{
			if (contena[-w] > 0){
				contena[-w]--;
				//std::cout << -w << "minus" << std::endl;
			}
			//contena.erase(std::remove(contena.begin(), contena.end(), -w),contena.end());
		}
	}
	int ans = 0;
	for (int i = 1; i <= m; ++i){
		if (contena[i] != 0){
			ans += contena[i];
			//std::cout << i<<" "<<contena[i] <<std::endl;
		}
	}
		
	std::cout << ans << std::endl;
	return 0;
}
0