結果

問題 No.59 鉄道の旅
ユーザー tkzw_21tkzw_21
提出日時 2015-03-24 12:29:47
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 953 bytes
コンパイル時間 1,264 ms
コンパイル使用メモリ 145,660 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-26 05:37:47
合計ジャッジ時間 8,023 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
template <class T>
struct BIT{
    int N;vector<T>bit;
    BIT(int n):N(n),bit(n+1){}
    void add(T k,int i){i++;for(int x=i;x<=N;x+=x&-x)bit[x]+=k;}
    T sum(int i){i++;T r=0;for(int x=i;x>0;x-=x&-x)r+=bit[x];return r;}
    T sum(int l,int r){return l<=r ? sum(r)-sum(l-1):sum(r)+sum(l,N-1);}
    T get(int i){return sum(i) - sum(i-1);}
    void set(T k,int i){add(k-get(i),i);}
};
int main(void) {
	int N,K;
	cin >> N >> K;
	BIT<int> bit(100001);
	vector<int> cnt(100001);
	int ret = 0;
	for(int i=0;i<N;i++){
		int w;cin >> w;
		if(w > 0){
			//すでにその荷物の重さ以上の荷物がK個以上列車に積まれているx
			if(  bit.sum(w,100001) >= K )continue;
			cnt[w]++;
			bit.add(1,w);
			ret++;
		}else{

			if(cnt[-w] > 0){
				cnt[-w]--;
				bit.add(-1,-w);
				ret--;
			}
		}
	}
	cout << ret << endl;
	return 0;
}
0