#include<bits/stdc++.h> using namespace std; struct node{ int ai,bi; }d[100010]; bool cmp(node x,node y){ return x.ai<y.ai; } int main(){ int n,m; cin>>n>>m; for(int i=0;i<m;++i){ scanf("%d %d",&d[i].ai,&d[i].bi); } sort(d,d+m,cmp); for(int i=0;i<m;++i){ if(n-d[i].ai<0) break; n+=d[i].bi; } cout<<n<<endl; return 0; } |
Double click to view unformatted code.