fork(5) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main ()
  8.  
  9. {
  10. ios_base::sync_with_stdio(0);
  11.  
  12. int trasa, ile;
  13. int odl, koszt, odlmax, odleg, min, minO, minN;
  14. long long suma, sumamin;
  15. vector < int > Vodl;
  16. vector < int > Vkoszt;
  17.  
  18. cin >> trasa >> ile;
  19. sumamin=0;
  20. for (int n=1; n<=ile; n++)
  21. {
  22. cin >> odl >> koszt;
  23. Vodl.push_back(odl);
  24. Vkoszt.push_back(koszt);
  25. odlmax=odl;
  26. }
  27. odleg=odlmax-800;
  28. min=999999999;
  29. minO=0;
  30. int n=ile-1;
  31. if (odlmax<=800)
  32. cout << 0 << endl;
  33. else
  34. {
  35. while (Vodl[n]>=800)
  36. {
  37. while (Vodl[n]>=odleg)
  38. {
  39. // cout << Vodl[n] << endl;
  40. if (Vkoszt[n]<=min)
  41. {
  42. min=Vkoszt[n];
  43. minO=Vodl[n];
  44. minN=n;
  45. // cout << min << " " << minO << " " << n << " " << odleg << endl;
  46. }
  47. n=n-1;
  48. if (n<0)
  49. break;
  50. }
  51. // cout << "1 " << min << " " << minO << " " << n << " " << odleg << endl;
  52. odleg=minO-800;
  53. sumamin=sumamin+min;
  54. min=999999999;
  55. minO=0;
  56. minN=n;
  57. }
  58. if (n>0)
  59. {
  60. while (n>0)
  61. {
  62. if (Vkoszt[n]<=min)
  63. min=Vkoszt[n];
  64. // cout << n << " " << Vkoszt[n] << endl;
  65. n=n-1;
  66. }
  67. sumamin=sumamin+min;
  68. }
  69. cout << sumamin << endl;
  70. }
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0s 15360KB
stdin
Standard input is empty
stdout
0