結果

問題 No.817 Coin donation
ユーザー kuuso1kuuso1
提出日時 2019-04-19 22:58:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 448 ms / 2,000 ms
コード長 1,839 bytes
コンパイル時間 2,846 ms
コンパイル使用メモリ 113,004 KB
実行使用メモリ 85,544 KB
最終ジャッジ日時 2023-10-24 10:12:16
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
26,384 KB
testcase_01 AC 32 ms
26,392 KB
testcase_02 AC 33 ms
26,396 KB
testcase_03 AC 34 ms
26,396 KB
testcase_04 AC 32 ms
26,396 KB
testcase_05 AC 43 ms
27,548 KB
testcase_06 AC 83 ms
41,616 KB
testcase_07 AC 95 ms
42,532 KB
testcase_08 AC 315 ms
73,772 KB
testcase_09 AC 108 ms
45,748 KB
testcase_10 AC 448 ms
85,544 KB
testcase_11 AC 440 ms
85,540 KB
testcase_12 AC 436 ms
85,540 KB
testcase_13 AC 31 ms
26,384 KB
testcase_14 AC 31 ms
26,384 KB
testcase_15 AC 32 ms
26,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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