結果

問題 No.1715 Dinner 2
ユーザー abc3
提出日時 2021-10-23 00:08:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,431 bytes
コンパイル時間 2,602 ms
コンパイル使用メモリ 203,720 KB
最終ジャッジ日時 2025-01-25 04:38:28
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 34 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const ll INF=1001001001;
    const int mod=998244353;
    
    void solve(){
        int n,d;
        cin>>n>>d;
        vector<P>p(n);
        rep(i,n){
            cin>>p[i].first>>p[i].second;
        }
        sort(p.rbegin(),p.rend());
        auto f=[&](int mid){
            vector<P>plus,minus;
            rep(i,n){
                if(p[i].second-p[i].first>=0){plus.push_back({-p[i].first,-p[i].first+p[i].second});}
                else{minus.push_back({-p[i].first,-p[i].first+p[i].second});}
            }
            sort(plus.rbegin(),plus.rend());
            sort(minus.rbegin(),minus.rend());
            if(plus.size()>1){
                int now=0,ok=1;
                rep(i,d){
                    int j=i%2;
                    if(now+plus[j].first<mid){ok=0;}
                    now+=plus[j].second;
                }
                if(ok){return true;}
            }
            if(minus.size()>1){
                int now=0,ok=1;
                rep(i,d){
                    int j=i%2;
                    if(now+minus[j].first<mid){ok=0;}
                    now+=minus[j].second;
                }
                if(ok){return true;}
            }
            if(plus.size()>0&&minus.size()>0){
                int now=0,ok=1;
                rep(i,d){
                    int m=(i%2==0?plus[0].first:minus[0].first);
                    int add=(i%2==0?plus[0].second:minus[0].second);
                    if(now+m<mid){ok=0;}
                    now+=add;
                }
                if(ok){return true;}
            }
            return false;
        };

        int l=-INF,r=0;
        while(r-l>1){
            int mid=(l+r)/2;
            if(f(mid)){l=mid;}
            else{r=mid;}
        }
        cout<<l<<endl;
    } 

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();

        return 0;
    }
0