传送门
文章目录
- 题意:
- 思路:
题意:
思路:
比较直观的想法就是对于bi≥0b_i\ge0bi≥0的项目,我们将aia_iai从小到大排序,让后依次加bib_ibi,如果有取不到的,显然就无解。否则再看bi<0b_i<0bi<0的部分,这部分不是很好处理,我们尝试推一下狮子。
假设有两个相邻的项目i,ji,ji,j,他们的b<0b<0b<0,当前分为sumsumsum,使用临项交换法,先考虑两种情况:
(1)(1)(1)当iii在jjj前面的时候,需要满足sum≥ai,sum+bi≥ajsum\ge a_i,sum+b_i\ge a_jsum≥ai,sum+bi≥aj,即sum≥max(ai,aj−bi)sum\ge max(a_i,a_j-b_i)sum≥max(ai,aj−bi)。
(2)(2)(2)当jjj在iii前面的时候,需要满足sum≥aj,sum+bj≥aisum\ge a_j,sum+b_j\ge a_isum≥aj,sum+bj≥ai,即sum≥max(aj,ai−bj)sum\ge max(a_j,a_i-b_j)sum≥max(aj,ai−bj)。
假设iii在jjj前面更优的话,那么也就是max(ai,aj−bi)≤max(aj,ai−bj)max(a_i,a_j-b_i)\le max(a_j,a_i-b_j)max(ai,aj−bi)≤max(aj,ai−bj),注意到ai≤ai−bj,aj≤aj−bia_i\le a_i-b_j,a_j\le a_j-b_iai≤ai−bj,aj≤aj−bi,那么上面的式子也就变成aj−bi≤ai−bja_j-b_i\le a_i-b_jaj−bi≤ai−bj,移项得aj+bj≤ai+bia_j+b_j\le a_i+b_iaj+bj≤ai+bi,所以对于b<0b<0b<0的部分,我们按照ai+bia_i+b_iai+bi从大到小排序即可。
// Problem: F1. Complete the Projects (easy version)
// Contest: Codeforces - Codeforces Round #579 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1203/F1
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;LL n,m;
struct Node {int a,b;
};
vector<Node>v1,v2;bool cmp1(Node a,Node b) {return a.a<b.a;
}bool cmp2(Node a,Node b) {return a.a+a.b>b.a+b.b;
}bool check() {int cnt=0;for(auto x:v1) {if(m>=x.a) m+=x.b,cnt++;else break;}if(cnt!=v1.size()) return false;cnt=0;for(auto x:v2) {if(m>=x.a) m+=x.b,cnt++;else break;}if(m<0) return false;if(cnt!=v2.size()) return false;return true;
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);scanf("%lld%lld",&n,&m);for(int i=1;i<=n;i++) {int a,b; scanf("%d%d",&a,&b);if(b>=0) v1.pb({a,b});else v2.pb({a,b});}sort(v1.begin(),v1.end(),cmp1);sort(v2.begin(),v2.end(),cmp2);if(check()) puts("YES");else puts("NO");return 0;
}
/**/