結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  puni_kyopro | 
| 提出日時 | 2019-08-16 19:47:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                CE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 2,367 bytes | 
| コンパイル時間 | 970 ms | 
| コンパイル使用メモリ | 80,032 KB | 
| 最終ジャッジ日時 | 2025-04-21 08:41:38 | 
| 合計ジャッジ時間 | 1,977 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:47:17: error: ‘INT32_MAX’ was not declared in this scope
   47 | const int INF = INT32_MAX / 3;
      |                 ^~~~~~~~~
main.cpp:13:1: note: ‘INT32_MAX’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
   12 | #include<climits>
  +++ |+#include <cstdint>
   13 | 
            
            ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
/******************************************************************************************/
//BinaryIndexTree(siz):長さsizで初期化
//sum(k):区間[0,k]の和を求める
//add(k,x):要素kにxを加える
template<typename T>
struct BinaryIndexTree {
	vector<T> data;
	BinaryIndexTree(int siz)
	{
		//1-indexなので配列は1つ多めに用意する
		data.resize(siz + 1, 0);
	}
	T sum(int k)
	{
		//a_1~a_kまでの和を計算
		T ret = 0;
		for (int i = k; i > 0; i -= (i & -i))
		{
			ret += data[i];
		}
		return ret;
	}
	void add(int k, int x)
	{
		//a_kにxを加算する
		for (int i = k; i < data.size(); i += (i & -i))
		{
			data[i] += x;
		}
	}
};
int main() {
	int n, k;
	cin >> n >> k;
	vector<int> w(n);
	for (int i = 0; i < n; i++)
	{
		cin >> w[i];
	}
	BinaryIndexTree<int> bit(1000005);
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (w[i] > 0) {
			if (bit.sum(1000005) - bit.sum(w[i] - 1) < k) {
				bit.add(w[i],1);
				ans++;
			}
		}
		else
		{
			if (bit.sum(-w[i]) - bit.sum(-w[i] - 1) >= 1) {
				bit.add(-w[i], -1);
				ans--;
			}
		}
		
	}
	cout << ans << endl;
	
	return 0;
}
            
            
            
        