fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7.  
  8. void solve(){
  9. int n, k, l;
  10. cin >> n >> k >> l;
  11.  
  12. queue<int> q;
  13.  
  14. for(int i = 0; i < n; i++){
  15. int x;
  16. cin >> x;
  17. q.push(x);
  18. }
  19.  
  20. double t = q.front();
  21. q.pop();
  22. double dist = k;
  23. double prev = 0;
  24. while(dist < l && q.size()){
  25. while(dist < l && q.size() && q.front() - t <= dist){
  26. if(q.front() < dist){
  27. prev = min(dist, q.front() + t);
  28. }else prev = dist;
  29. if(dist - prev < k)dist = prev + k;
  30.  
  31. q.pop();
  32. }
  33. if(dist - prev >= k){
  34. int need = dist - k - prev;
  35. t += need;
  36. prev += need;
  37. }
  38. if(q.size() && dist < l){
  39. double x = q.front() - t;
  40. double req = (x + dist) / 2 - dist;
  41. t += req;
  42. dist += req;
  43. }
  44. }
  45.  
  46. if(dist >= l){
  47. cout << floor(2 * t) << "\n";
  48. }else{
  49.  
  50. double need = max(0.0, l - k - prev);
  51. t += need;
  52. cout << floor(2 * t) << "\n";
  53. }
  54.  
  55. }
  56.  
  57. int main(){
  58. ios_base::sync_with_stdio(false);
  59. cin.tie(nullptr);
  60.  
  61. int t = 1;
  62. cin >> t;
  63.  
  64. for(int i = 1; i <= t; i++){
  65. solve();
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0s 5292KB
stdin
9
1 3 5
0
3 2 5
2 5 5
1 10 10
10
10 1 10
0 1 2 3 4 5 6 7 8 9
2 1 2
0 0
2 1 2
0 2
2 1 3
0 2
2 2 4
1 1
9 12 54
3 3 8 24 25 27 29 34 53
stdout
4
5
20
0
2
1
2
2
7