Links: https://ac.nowcoder.com/acm/contest/2272/H
Source: Cattle-off network
space restrictions: C / C ++ 131072K, other languages 262144K
64bit the IO the Format: LLD%
Title Description
Pa autumn Li mastered the magic soil properties
She uses this magic to build a large ball of earth, and let it go all the way to the crash barriers
There is a ball of soil stability x, if x <0, it will fall apart at once
After each collision obstacle, soil ball will lose the stability ai, collision, stability will bi back from the barrier body
Pa autumn Li wondered if reasonable order arrange obstacles, in the case of soil to ensure the ball does not fall apart, whether it be crashing all the obstacles?
Enter a description:
Enter an integer T, T represents a group of data, each set of data:
the front row of two integers n, m, represents the number of barriers and stability of the soil ball
next row of two integers, respectively, ai and bi disorders
Output Description:
If so, output "Yes" (without the quotes), otherwise the output "No" (without the quotes)
Remarks:
Σn <= 500000, 1 <= m <= 100000,0 <= a, b <= 100000
thinking: Author: _tqr
link: https://ac.nowcoder.com/discuss/346888
Source: Cattle customer network
ideas:
Obviously greed
If the soil ball hit obstacles will not broken, then try to select the reply - consume more obstacles
If you can return to the blood, then the preference of consumption is minimized;
If the return is less than the consumption of blood, so the blood back up to first choice
In the above operation, the event can not be selected, can not satisfy the conditions of Analyzing
Sort you can sort only part of ah! ! ! How I did not think so before! ! !
Look at the code:
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> using namespace std; typedef long long LL; const int maxn=5e5+5; const int maxm=100000+10; struct Node { LL a,b,c; }a[maxn]; bool cmp1(const Node x,const Node y) { return x.c>y.c; } bool cmp2(const Node x,const Node y) { return x.a<y.a; } bool cmp3(const Node x,const Node y) { return x.b>y.b; } int main() { LL T,N,M,sum;scanf("%lld",&T); while(T--) { sum=0; scanf("%lld%lld",&N,&M); for(int i=0; I <N; I ++ ) { Scanf ( " %% LLD LLD " , & A [I] II.A, & A [I] .B); A [I] .c = A [I] .b- A [I] II.A; IF (A [I] .c> 0 ) SUM ++ ; } // IF (SUM == N) {the printf ( "Yes \ n-"); Continue;} Sort (A, A + N, CMP1); / / after before after sorting a sum back to the blood are increased stability // case before a small sum piggy small to large losses Sort (a, a + sum, CMP2); // remaining N-sum back to the blood are all th after the stability will be reduced, but we removed all the obstacles so large blood back preference Sort (SUM a +, a + N, CMP3); int in Flag =0; for(int i=0;i<N;i++) { if(M<a[i].a) { flag=1;break; } M+=a[i].c; } if(flag==1) printf("No\n"); else printf("Yes\n"); } return 0; } /** */