a53

credite

a53
Aug 30th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. #define NMAX 10001
  4. using namespace std;
  5. ifstream f("credite.in");
  6. ofstream g("credite.out");
  7. struct Credite
  8. {
  9. int credit,timp;
  10. };
  11. Credite lista[NMAX];
  12. int n;
  13.  
  14. bool cmp(Credite x,Credite y)
  15. {
  16. return x.credit>y.credit;
  17. }
  18.  
  19. int cauta(int i)
  20. {
  21. int j=1;
  22. while(j<=n&&i>lista[j].timp)
  23. ++j;
  24. if(j>n)
  25. return -1;
  26. return j;
  27. }
  28.  
  29. void sterge(int x)
  30. {
  31. lista[x].credit=lista[x].timp=-1;
  32. }
  33.  
  34. int main()
  35. {
  36. int i,crmax=0,x;
  37. f>>n;
  38. for(i=1;i<=n;++i)
  39. {
  40. f>>lista[i].credit>>lista[i].timp;
  41. if(crmax<lista[i].timp)
  42. crmax=lista[i].timp;
  43. }
  44. sort(lista+1,lista+n+1,cmp);
  45. int s=0;
  46. for(i=crmax;i>0;--i)
  47. {
  48. x=cauta(i);
  49. if(x>0)
  50. {
  51. s+=lista[x].credit;
  52. sterge(x);
  53. }
  54. }
  55. g<<s<<'\n';
  56. return 0;
  57. }
Add Comment
Please, Sign In to add comment