結果

問題 No.817 Coin donation
ユーザー kuuso1
提出日時 2019-04-19 22:58:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 1,839 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 116,048 KB
実行使用メモリ 88,544 KB
最終ジャッジ日時 2024-09-23 02:39:33
合計ジャッジ時間 4,097 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var hs = new HashSet<long>();
		for(int i=0;i<N;i++){
			for(int k=-1;k<=1;k++){
				hs.Add(A[i] + k);
				hs.Add(B[i] + k);
			}
		}
		
		var l = hs.ToList();
		l.Sort();
		var di = new Dictionary<long, int>();
		for(int i=0;i<l.Count;i++){
			di.Add(l[i], i);
		}
		
		int NN = l.Count;
		long[] imos = new long[NN + 1];
		for(int i=0;i<N;i++){
			imos[di[A[i]]] += 1;
			imos[di[B[i]] + 1] += -1;
		}
		long[] sum = new long[NN + 1];
		for(int i=1;i<=NN;i++){
			sum[i] = imos[i] + sum[i - 1];
		}
		
		long tot = 0;
		for(int i=0;i<NN-1;i++){
			long ntot = tot + sum[i] * (l[i + 1] - l[i]);
			if(ntot < K){
				tot = ntot;
				continue;
			}
			
			var rest = K - tot;
			long mm = (rest + sum[i] - 1) / sum[i];
			Console.WriteLine(l[i] + mm - 1);
			return;
			
			
		}
		
		
	}
	int N;
	long K;
	long[] A, B;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		A = new long[N];
		B = new long[N];
		for(int i=0;i<N;i++){
			d = ria();
			A[i] = d[0]; B[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0