fork(6) download
  1. using namespace std;
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <queue>
  6.  
  7. int N,M,L;
  8.  
  9. int main() {
  10. cin >> N >> M >> L;
  11.  
  12. int curLimit = 0;
  13. queue<int> q;
  14. int ans = 0;
  15. // cout << "done" << endl;
  16. for(int i = 0;i < N;++i) {
  17. int cur;
  18. cin >> cur;
  19. int last = -1;
  20. while(q.size() > 0 && q.front() < cur) {
  21. curLimit--;
  22. last = q.front();
  23. q.pop();
  24. }
  25. if(last != - 1 && curLimit == 0) {
  26. ans += cur - last - 1;
  27. }
  28. if(curLimit == L) {
  29. q.push(q.front() + M);
  30. q.pop();
  31. }
  32. if(curLimit < L) {
  33. q.push(cur + M - 1);
  34. curLimit++;
  35. }
  36. }
  37. cout << ans << endl;
  38. }
Success #stdin #stdout 0s 4544KB
stdin
Standard input is empty
stdout
0