Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("lupu.in");
  8. ofstream fout("lupu.out");
  9.  
  10. struct oaie
  11. {
  12. long long dist, lana, timp;
  13. bool operator<(oaie rhs) const
  14. {
  15. return lana<rhs.lana;
  16. }
  17. } p[100002];
  18.  
  19. bool comp_t(oaie s, oaie dr)
  20. {
  21. return s.timp>dr.timp;
  22. }
  23.  
  24. priority_queue<oaie> q;
  25. long long N, X, L, ans, tmax;
  26. int main()
  27. {
  28. fin>>N>>X>>L;
  29. for (int i=1; i<=N; i++)
  30. {
  31. fin>>p[i].dist;
  32. fin>>p[i].lana;
  33. p[i].timp = (X-p[i].dist)/L;
  34. if (p[i].timp>tmax)
  35. tmax = p[i].timp;
  36. }
  37.  
  38. sort(p+1,p+N+1, comp_t);
  39.  
  40. long long pos = 1;
  41. for (long long d=tmax; d>=0; d--)
  42. {
  43. while (pos<=N && p[pos].timp==d)
  44. {
  45. q.push(p[pos]);
  46. pos++;
  47. }
  48. if (!q.empty())
  49. {
  50. ans+=q.top().lana;
  51. q.pop();
  52. }
  53. }
  54. fout<<ans;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement