結果

問題 No.59 鉄道の旅
コンテスト
ユーザー 184
提出日時 2014-11-07 00:29:45
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 778 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 693 ms
コンパイル使用メモリ 92,908 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2026-05-30 14:44:36
合計ジャッジ時間 8,168 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>  
#include <iostream>
#include <vector>
#include <string>
#include <algorithm> 
#include <map>

using namespace std;
//namaega184
 
int main(){
	int n,k;scanf("%d%d",&n,&k); 
	// int w[1000001]={};
	int a;
	map<int,int> mp;
	long long ans=0;
	long long over=0;
	long long total=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		if(a<0){
			a=-a;
			if(mp[a]>0){
				mp[a]--;
				total-=a;
			}
		}
		else{
			int num=0;
			for(auto it=mp.begin();it!=mp.end();it++){
				if(it->first<a)continue;
				num+=it->second;
				if(num>=k)break;
			}
			if(num>=k)continue;
			mp[a]++;
			total+=a;
		}
	}
	for(auto it=mp.begin();it!=mp.end();it++){
		ans+=it->second;
	}
	printf("%lld\n",ans);
	return 0;
}
0