fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n ; cin>>n;
  7. int maxpkts; cin>>maxpkts;
  8. int rate ; cin>>rate;
  9. vector<vector<int>>requests(n,vector<int>(2));
  10. for(int i = 0 ;i<n;i++){
  11. cin>>requests[i][0]>>requests[i][1];
  12. }
  13. int dropped = 0;
  14. int pipeline = 0 ;
  15. for(int i = 0 ;i<n;i++){
  16. if(i==0){
  17. if(requests[i][1]>maxpkts){
  18. int diff = requests[i][1]-maxpkts;
  19. dropped+=diff;
  20. }
  21. else{
  22. pipeline += requests[i][1];
  23. }
  24. }
  25. else{
  26. int time = requests[i][0]-requests[i-1][0];
  27. if(pipeline-(time*rate)<0){
  28. pipeline = 0 ;
  29. }
  30. else{
  31. pipeline -= time*rate ;
  32. }
  33. if(pipeline+requests[i][1]>maxpkts){
  34. int diff = pipeline+requests[i][1]-maxpkts;
  35. dropped +=diff;
  36. pipeline = maxpkts;
  37. }
  38. else{
  39. pipeline = pipeline+requests[i][1];
  40. }
  41. }
  42. }
  43. cout<<dropped;
  44.  
  45. // your code goes here
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5324KB
stdin
3
10
2
1 8 
4 9 
6 7 
stdout
4