MinhNGUYEN2k4

Untitled

Dec 2nd, 2021
597
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void readfile()
  2. {
  3.     ios_base::sync_with_stdio(false);
  4.     cin.tie(0);cout.tie(0);
  5.     if (fopen(Task".inp","r"))
  6.     {
  7.         freopen(Task".inp","r",stdin);
  8.         freopen(Task".out","w",stdout);
  9.     }
  10.     cin >> k;
  11.     cin >> n;
  12.     for(int i=1; i<=n; i++) cin >> a[i];
  13. }
  14.  
  15. void proc()
  16. {
  17.     double prev_time = 0;
  18.     for(int i=1; i<=n; i++){
  19.         //first i person consume prev_time
  20.         //if i+1 can hear i lesser than prev_time
  21.         if (a[i+1] - prev_time < a[i]+k+1e-9) a[i+1] = max(a[i]+k,a[i+1]-prev_time);
  22.         //else i+1 must run to the left prev_time distances
  23.         else a[i+1]-=prev_time;
  24.         prev_time += max(0.0,(a[i+1]-a[i]-k)/2);
  25.         a[i+1] -= max(0.0,(a[i+1]-a[i]-k)/2);
  26.     }
  27.     cout << setprecision(6) << fixed << prev_time;
  28. }
RAW Paste Data