修炼
修炼
http://www.nowcoder.com/questionTerminal/426ed72bde22405ab6d4f3cb758f937d
代码:
#include<iostream> #include<cmath> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; struct fun{ int b1; int b2; }; bool cmp(fun x,fun y){ return x.b1+x.b2<y.b1+y.b2; } int main() { fun c[1005]; int a1,a2,n,v1=0,v2=0,ans=0,i; cin>>a1>>a2; cin>>n; for(i=0;i<n;i++){ cin>>c[i].b1>>c[i].b2; } sort(c,c+n,cmp); while(1){ a1++; a2++; v1+=a1; v2+=a2; ans++; for(i=0;v1+v2>=c[i].b1+c[i].b2;i++){ if(v1>=c[i].b1&&v2>=c[i].b2) {cout<<ans<<endl; return 0;} } } return 0; }