結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-05-22 00:35:17 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 22 ms / 5,000 ms | 
| コード長 | 714 bytes | 
| コンパイル時間 | 1,467 ms | 
| コンパイル使用メモリ | 158,044 KB | 
| 実行使用メモリ | 7,680 KB | 
| 最終ジャッジ日時 | 2024-12-24 20:37:47 | 
| 合計ジャッジ時間 | 2,372 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 12 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         int N, K; scanf("%d%d", &N, &K);
      |                   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:22:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         REP(i, N) scanf("%d", W + i);
      |                   ~~~~~^~~~~~~~~~~~~
            
            ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))
const int SIZE = 1000000 + 10;
int bit[SIZE+1];
int get(int idx) {
	int sum = 0;
	for (int x = idx + 1; x > 0; x -= x & -x) sum += bit[x];
	return sum;
}
void add(int idx, int val) {
	for (int x = idx + 1; x <= SIZE; x += x & -x) bit[x] += val;
}
int W[100000];
int main() {
	int N, K; scanf("%d%d", &N, &K);
	REP(i, N) scanf("%d", W + i);
	int CO = 1000000 + 1;
	REP(n, N) {
		int w = W[n];
		if (w > 0) {
			if (get(CO - w) < K) {
				add(CO - w, 1);
			}
		}
		else {
			w = -w;
			if (get(CO - w) - get(CO - w - 1) > 0) {
				add(CO - w, -1);
			}
		}
	}
	cout << get(SIZE) << endl;
}
            
            
            
        