結果

問題 No.1570 Blocks
ユーザー zhanghonghe2zhanghonghe2
提出日時 2021-06-27 17:07:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 80,560 KB
実行使用メモリ 7,184 KB
最終ジャッジ日時 2023-09-07 18:05:21
合計ジャッジ時間 4,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 28 ms
4,988 KB
testcase_03 AC 49 ms
6,804 KB
testcase_04 AC 25 ms
4,740 KB
testcase_05 AC 26 ms
4,872 KB
testcase_06 AC 38 ms
6,236 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 49 ms
6,764 KB
testcase_09 AC 56 ms
7,076 KB
testcase_10 AC 32 ms
5,292 KB
testcase_11 AC 35 ms
5,328 KB
testcase_12 AC 58 ms
7,124 KB
testcase_13 AC 40 ms
5,776 KB
testcase_14 AC 42 ms
5,684 KB
testcase_15 AC 19 ms
4,472 KB
testcase_16 AC 41 ms
5,780 KB
testcase_17 AC 24 ms
5,080 KB
testcase_18 AC 34 ms
5,264 KB
testcase_19 AC 24 ms
4,968 KB
testcase_20 AC 19 ms
4,392 KB
testcase_21 AC 44 ms
6,560 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 58 ms
7,104 KB
testcase_33 AC 59 ms
7,160 KB
testcase_34 AC 39 ms
5,496 KB
testcase_35 AC 58 ms
7,156 KB
testcase_36 AC 40 ms
5,576 KB
testcase_37 AC 55 ms
6,976 KB
testcase_38 AC 57 ms
6,900 KB
testcase_39 AC 42 ms
5,932 KB
testcase_40 AC 39 ms
5,616 KB
testcase_41 AC 58 ms
7,048 KB
testcase_42 AC 43 ms
5,808 KB
testcase_43 AC 43 ms
5,768 KB
testcase_44 AC 42 ms
5,728 KB
testcase_45 AC 43 ms
5,884 KB
testcase_46 AC 60 ms
7,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
using namespace std;

const int maxn=1e5+100;

struct node{
    int id;
    ll w, carry;
    bool operator < (const node& x)const{
        return w<x.w;
    }
};

bool cmp(node a,node b){
    return a.carry<b.carry;
}
node box[maxn];


priority_queue<node> q;

int main(){
    ios::sync_with_stdio(false);
    int N;cin>>N;
    ll sum=0;
    for(int i=1;i<=N;i++){
        cin>>box[i].w>>box[i].carry;
        box[i].carry+=box[i].w;
        sum+=box[i].w;
    }

    sort(box+1,box+1+N,cmp);

    int cnt=0;
    int last=N;
    while(cnt<N){
        int L=1;int R=N-cnt;
        while(L<=R){
            int mid=(L+R)>>1;
            if(box[mid].carry>=sum){
                R=mid-1;
            }else{
                L=mid+1;
            }
        }
        ll w=-1;
        int id=-1;
        for(int i=L;i<=last;i++){
            q.push(box[i]);
        }
        last=L-1;
        if(q.empty()) break;
        node x=q.top();
        q.pop();
        sum-=x.w;
        cnt+=1;
    }
    if(cnt==N){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}
0