結果

問題 No.1715 Dinner 2
ユーザー _san_yo
提出日時 2021-10-22 22:54:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,223 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 171,644 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-23 06:41:11
合計ジャッジ時間 2,755 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:53:9: warning: 'f' may be used uninitialized [-Wmaybe-uninitialized]
   53 |         if(!f){
      |         ^~
main.cpp:22:10: note: 'f' was declared here
   22 |     bool f;
      |          ^

ソースコード

diff #

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

typedef struct{
    ll p;
    ll q;
    ll num;
} CELL;

int cmp(CELL a, CELL b){
    if(a.q - a.p > b.q - b.p){
        return 1;
    }else{
        return 0;
    }
}

int main(){
    ll n,d,t,l = -100000000,r = 0,m,tm;
    CELL c[1000] = {};
    bool f;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        cin >> c[i].p >> c[i].q;
        c[i].num = i;
    }
    sort(c,c+n,cmp);
    while(l < r){
        m = (l+r)/2;
        tm = 0;
        t = -1;
        for(int i = 0; i < d; i++){
            f = true;
            for(int j = 0; j < n; j++){
                if(tm >= m + c[j].p && t != j){
                    t = j;
                    tm += c[j].q - c[j].p;
                    f = false;
                    break;
                }
            }
            if(f){
                if(r == m){
                    cout << l;
                    return 0;
                }else{
                    r = m;
                }
                break;
            }
        }
        if(!f){
            if(r == m){
                cout << r;
                return 0;
            }else{
                l = m;
            }
        }
    }
}
0