結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  184 | 
| 提出日時 | 2014-11-07 00:28:00 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 779 bytes | 
| コンパイル時間 | 764 ms | 
| コンパイル使用メモリ | 71,856 KB | 
| 実行使用メモリ | 10,112 KB | 
| 最終ジャッジ日時 | 2024-12-24 20:11:22 | 
| 合計ジャッジ時間 | 20,650 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 9 TLE * 3 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   44 |         printf("%I64d\n",ans);
      |                 ~~~~^    ~~~
      |                     |    |
      |                     int  long long int
      |                 %I64lld
main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         int n,k;scanf("%d%d",&n,&k);
      |                 ~~~~~^~~~~~~~~~~~~~
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |                 scanf("%d",&a);
      |                 ~~~~~^~~~~~~~~
            
            ソースコード
#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("%I64d\n",ans);
	return 0;
}
            
            
            
        