結果

問題 No.3761 Moonlit Battle
コンテスト
ユーザー simasima_71
提出日時 2026-10-09 22:17:56
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 58 ms / 2,000 ms
+ 62µs
コード長 1,705 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,642 ms
コンパイル使用メモリ 256,572 KB
実行使用メモリ 22,380 KB
最終ジャッジ日時 2026-10-09 22:18:08
合計ジャッジ時間 6,569 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
template<class T> using pq_ = priority_queue<T, vector<T>, greater<T>>;
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
using mint=modint998244353;
// g++ a.cpp -std=c++23 -I.
// g++ -std=c++23 -I. a.cpp -o main
// g++ -std=c++23 -I. anaive.cpp -o naive
// g++ -std=c++23 -I. agene.cpp -o gene


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n,d;
    cin>>n>>d;
    vl a(n);
    vl b(n);
    rep(i,0,n){
        cin>>a[i]>>b[i];
    }
    vector<array<ll,2>> e(n);
    rep(i,0,n){
        e[i]={b[i],a[i]};
    }
    sort(all(e));
    reverse(all(e));
    ll r=0;
    ll now=0;
    ll ans=0;
    rep(i,0,n){
        if(now+e[i][1]>=d){
            break;
        }
        else {
            r++;
            now+=e[i][1];
        }
    }
    if(r!=n)ans+=e[r][0];
    vector<array<ll,2>> g;
    rep(i,0,r){
        e[i][0]-=ans;
    }
    
    rep(i,0,r){
        ans+=e[i][0]/d*e[i][1];
        e[i][0]%=d;
        g.push_back({e[i][0],e[i][1]});
        
    }
    sort(all(g));
    
    if(r!=0)d=g[r-1][0];
    ll anss=ans;
    vl rui(r+1);
    rep(i,0,r){
        rui[i+1]+=rui[i]+g[i][1];
    }
    ans=ans+rui[r];
    rep(i,0,r){
        ans=min(ans,anss+g[i][0]+rui[r]-rui[i+1]);
        
    }
    cout<<ans<<endl;
}
0