結果
| 問題 | No.3761 Moonlit Battle |
| コンテスト | |
| ユーザー |
kyoprouno
|
| 提出日時 | 2026-10-04 03:24:29 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 182 ms / 2,000 ms |
| + 991µs | |
| コード長 | 1,363 bytes |
| 記録 | |
| コンパイル時間 | 2,262 ms |
| コンパイル使用メモリ | 370,880 KB |
| 実行使用メモリ | 24,168 KB |
| 最終ジャッジ日時 | 2026-10-09 20:52:10 |
| 合計ジャッジ時間 | 6,906 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
#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);
vector<pair<ll,ll>> c(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];
c[i].first = b[i];
c[i].second = a[i];
}
sort(c.begin(),c.end());
ll threshold = n;
for(int i = 0; i < n; i++){
if(sum < d){
threshold = i;
break;
}
sum -= c[i].second;
}
set<ll> s;
s.insert(threshold);
s.insert(max(0LL,threshold-1));
ll ans = INF;
for(auto x:s){
ll sub = 0;
if(x)sub = c[x-1].first;
ll total = sub;
vector<pair<ll,ll>> r;
for(int i = x; i < n; i++){
if(c[i].first <= sub)continue;
total += (c[i].first - sub + d - 1) / d * c[i].second;
pair<ll,ll> r_cand;
r_cand.first = (c[i].first - 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 y:r){
total += y.first - p;
p = y.first;
total -= c[y.second].second;
chmin(ans,total);
}
}
cout << ans << endl;
};
int main() {
int t = 1;
// cin >> t;
while(t--) main_();
return 0;
}
kyoprouno