結果

問題 No.3761 Moonlit Battle
コンテスト
ユーザー kyoprouno
提出日時 2026-10-04 03:04:29
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,244 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,891 ms
コンパイル使用メモリ 367,524 KB
実行使用メモリ 14,312 KB
最終ジャッジ日時 2026-10-09 20:52:05
合計ジャッジ時間 6,559 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }

const ll INF = 1e15;


void main_() {
	int n,d;
	cin >> n >> d;
	vector<int> a(n), b(n);

	ll sum = 0;

	ll cnt = 0;

	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		sum += a[i];
		cnt += (b[i] + d - 1)/d * a[i];
	}

	ll threshold = n;

	for(int i = 0; i < n; i++){
		if(sum < d){
			threshold = i;
			break;
		}
		sum -= a[i];
	}

	set<ll> s;

	s.insert(threshold);
	s.insert(max(0LL,threshold-1));

	ll ans = INF;

	for(auto x:s){
		ll sub = 0;
		if(threshold)sub = b[threshold-1];
		ll total = sub;
		vector<pair<ll,ll>> r;
		for(int i = threshold; i < n; i++){
			if(b[i] <= sub)continue;
			total += (b[i] - sub + d - 1) / d * a[i];
			pair<ll,ll> r_cand;
			r_cand.first = (b[i] - sub) % d;
			if(r_cand.first == 0)r_cand.first = d;
			r_cand.second = i;

			r.push_back(r_cand); 
		}
		sort(r.begin(),r.end());
		ll p = 0;
		chmin(ans,total);
		for(auto x:r){
			total += x.first - p;
			p = x.first;
			total -= a[x.second];
			chmin(ans,total);
		}

	}
	cout << ans << endl;

};

 
int main() {
	int t = 1;
	// cin >> t;
	while(t--) main_();
	return 0;
}
0