fork download
  1. #include<stdio.h>
  2. #include<algorithm>
  3. struct ss
  4. {
  5. int day;
  6. int cap;
  7. };
  8. struct cc
  9. {
  10. bool operator()(struct ss ob1,struct ss ob2)
  11. {
  12. return ob1.day>ob2.day;
  13. }
  14. }comp;
  15. int main()
  16. {
  17. int n,c,ct=0,val,j,it,i,flag=0;
  18. int cap;
  19. int arr[100009];
  20. int maxi=-1e9;
  21. int day[100009];
  22. struct ss st[100009];
  23. scanf("%d%d",&n,&cap);
  24. for(i=0;i<n;i++)
  25. {
  26. scanf("%d%d",&st[i].day,&st[i].cap);
  27. day[st[i].day]=st[i].cap;
  28. if(st[i].day>maxi)
  29. maxi=st[i].day;
  30. }
  31. int s=0;
  32. for(i=1;i<=maxi+1;i++)
  33. {
  34. //printf("day[i-1]=%d day[i]=%d\n",day[i-1],day[i]);
  35. if(cap>day[i-1])
  36. {
  37. if(day[i]>cap-day[i-1])
  38. {
  39. day[i]=day[i]-(cap-day[i-1]);
  40. s+=cap;
  41. }
  42. else
  43. {
  44. s+=day[i-1]+day[i];
  45. day[i]=0;
  46.  
  47. }
  48. day[i-1]=0;
  49. // printf("up day[i]=%d i=%d\n",day[i],i);
  50.  
  51. // printf("i=%d day[i]=%d cap-day[i-1]=%d\n",i,day[i],cap-day[i-1]);
  52.  
  53.  
  54. }
  55. else
  56. {
  57. if(day[i-1]>cap)
  58. {
  59. s+=cap;
  60. day[i-1]=day[i-1]-cap;
  61.  
  62. }
  63. else
  64. {
  65. s+=day[i-1];
  66. day[i-1]=0;
  67.  
  68. }
  69. //day[i]+=day[i-1];
  70.  
  71. }
  72. //printf("i=%d s=%d\n",i,s);
  73. //printf("dwn day[i-1]=%d day[i]=%d i=%d\n",day[i-1],day[i],i);
  74. }
  75. printf("%d\n",s);
  76. return 0;
  77. }
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
0