結果

問題 No.1570 Blocks
ユーザー zhanghonghe2zhanghonghe2
提出日時 2021-06-27 16:59:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,139 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 75,784 KB
実行使用メモリ 9,276 KB
最終ジャッジ日時 2023-09-07 18:05:11
合計ジャッジ時間 10,152 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 26 ms
4,428 KB
testcase_03 AC 1,871 ms
4,676 KB
testcase_04 AC 22 ms
4,492 KB
testcase_05 AC 24 ms
4,456 KB
testcase_06 AC 1,191 ms
4,400 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 1,802 ms
4,908 KB
testcase_09 TLE -
testcase_10 AC 29 ms
4,884 KB
testcase_11 AC 32 ms
5,004 KB
testcase_12 TLE -
testcase_13 AC 37 ms
4,984 KB
testcase_14 AC 38 ms
4,916 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 37 ms
4,904 KB
testcase_17 AC 558 ms
4,376 KB
testcase_18 AC 30 ms
4,804 KB
testcase_19 AC 564 ms
4,380 KB
testcase_20 AC 17 ms
4,380 KB
testcase_21 AC 1,503 ms
4,500 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 AC 35 ms
5,124 KB
testcase_35 TLE -
testcase_36 AC 36 ms
4,848 KB
testcase_37 TLE -
testcase_38 TLE -
testcase_39 AC 37 ms
4,904 KB
testcase_40 AC 36 ms
4,972 KB
testcase_41 TLE -
testcase_42 AC 38 ms
4,996 KB
testcase_43 AC 39 ms
4,996 KB
testcase_44 AC 39 ms
5,136 KB
testcase_45 AC 39 ms
4,940 KB
testcase_46 TLE -
権限があれば一括ダウンロードができます

ソースコード

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{
    ll w, carry;
};

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

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;
    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<=N-cnt;i++){
            if(box[i].w>w){
                w=box[i].w;
                id=i;
            }
        }
        if(w==-1){
            break;
        }
        sum-=w;
        swap(box[N-cnt],box[id]);
        cnt+=1;
    }
    if(cnt==N){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}
0