#include<iostream> #include<algorithm> using namespace std; struct Per{ int a; int b; }; Per p[100010]; bool comp(Per lhs,Per rhs){ return lhs.a<rhs.a; } int main(){ int n,m; while(cin>>n>>m){ for(int i=0;i<m;i++){ cin>>p[i].a>>p[i].b; } sort(p,p+m,comp); for(int i=0;i<m;i++){ if(n>=p[i].a){ n+=p[i].b; } } cout<<n<<endl; } } |
Double click to view unformatted code.