結果
問題 | No.1570 Blocks |
ユーザー |
|
提出日時 | 2021-06-27 16:59:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,139 bytes |
コンパイル時間 | 742 ms |
コンパイル使用メモリ | 76,552 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-25 11:52:45 |
合計ジャッジ時間 | 31,369 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 TLE * 9 |
ソースコード
#include <iostream>#include <cstring>#include <algorithm>#include <queue>#include <vector>#define ll long longusing 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;}