結果

問題 No.817 Coin donation
ユーザー ohreitetsuohreitetsu
提出日時 2019-04-23 21:58:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,613 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 74,284 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-08-05 20:50:41
合計ジャッジ時間 14,850 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 1,380 ms
4,380 KB
testcase_03 AC 1,274 ms
4,380 KB
testcase_04 AC 1,052 ms
4,380 KB
testcase_05 AC 788 ms
4,376 KB
testcase_06 AC 1,179 ms
4,380 KB
testcase_07 AC 400 ms
4,380 KB
testcase_08 AC 942 ms
4,380 KB
testcase_09 AC 400 ms
4,380 KB
testcase_10 AC 1,613 ms
4,600 KB
testcase_11 AC 1,605 ms
4,676 KB
testcase_12 AC 1,612 ms
4,636 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
struct X{
	LL A;
	LL B;
};
bool Comp(X&l,X&r){
	if (l.A<r.A){
		return true;
	}else if (l.A==r.A){
		return l.B<r.B;
	}
	return false;
}
int main(int argc, char* argv[])
{
	LL N,K,i;
	cin>>N>>K;
	vector<X> AB(N);
	LL MaxV=0;
	LL MinV=10e10;
	for (i=0;i<N;i++){
		cin>>AB[i].A>>AB[i].B;
		if (MinV>AB[i].A){
			MinV=AB[i].A;
		}
		if (MaxV<AB[i].B){
			MaxV=AB[i].B;
		}
	}
	sort(AB.begin(),AB.end(),Comp);
	LL k=0;
	LL M=MinV;
	LL j=0;
	while (MinV<=MaxV){
		for (i=j;i<N;i++){
			if (M<AB[i].A){
				break;
			}
			if (M<=AB[i].B){
				k++;
			}
			if (k==K){
				cout<<M<<endl;
				return 0;
			}
		}
		M++;
		if (M>AB[j].B){
			j++;
		}
	}
	return 0;
}
0