Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #define NMAX 10001
- using namespace std;
- ifstream f("credite.in");
- ofstream g("credite.out");
- struct Credite
- {
- int credit,timp;
- };
- Credite lista[NMAX];
- int n;
- bool cmp(Credite x,Credite y)
- {
- return x.credit>y.credit;
- }
- int cauta(int i)
- {
- int j=1;
- while(j<=n&&i>lista[j].timp)
- ++j;
- if(j>n)
- return -1;
- return j;
- }
- void sterge(int x)
- {
- lista[x].credit=lista[x].timp=-1;
- }
- int main()
- {
- int i,crmax=0,x;
- f>>n;
- for(i=1;i<=n;++i)
- {
- f>>lista[i].credit>>lista[i].timp;
- if(crmax<lista[i].timp)
- crmax=lista[i].timp;
- }
- sort(lista+1,lista+n+1,cmp);
- int s=0;
- for(i=crmax;i>0;--i)
- {
- x=cauta(i);
- if(x>0)
- {
- s+=lista[x].credit;
- sterge(x);
- }
- }
- g<<s<<'\n';
- return 0;
- }
Add Comment
Please, Sign In to add comment