Submission #930241

# Submission time Handle Problem Language Result Execution time Memory
930241 2024-02-19T07:29:46 Z NeroZein Autobahn (COI21_autobahn) C++17
100 / 100
87 ms 20364 KB
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx2,fma")
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, x;
  cin >> n >> k >> x;
  vector<int> lp(n), t(n), rp(n);
  for (int i = 0; i < n; ++i) {
    cin >> lp[i] >> t[i] >> rp[i];
  }
  vector<array<int, 3>> pts;//second, pay, stay
  for (int i = 0; i < n; ++i) {
    if (rp[i] - lp[i] + 1 < t[i]) continue;
    pts.push_back({lp[i], 0, 1});
    pts.push_back({lp[i] + t[i], 1, 0});
    pts.push_back({rp[i] + 1, -1, -1});
  }
  vector<int> len;
  sort(pts.begin(), pts.end());
  vector<array<int, 3>> rng;//l, r, val
  int p = 0, s = 0;
  for (int i = 0; i < (int) pts.size() - 1; ++i) {
    auto [second, pay, stay] = pts[i];
    s += stay;
    p += pay; 
    int val = (s >= k ? p : 0);
    if (pts[i + 1][0] > second) {
      len.push_back({pts[i + 1][0] - second});
      rng.push_back({second, pts[i + 1][0] - 1, val});      
    }
  }
  long long ans = 0; 
  for (int rep = 0; rep < 2; ++rep) {
    //debug(len, rng);
    int r = -1;
    int curLen = 0; 
    long long curVal = 0; 
    int m = (int) rng.size(); 
    for (int l = 0; l < m; ++l) {
      while (r + 1 < m && curLen + len[r + 1] <= x) {
        curLen += len[r + 1];
        curVal += (long long) len[r + 1] * rng[r + 1][2];
        r++;
      }
      if (r < l) {
        curLen = curVal = 0; 
        ans = max(ans, (long long) x * rng[l][2]);
        r = l; 
        continue;
      }
      int space = x - curLen;
      if (r + 1 < m) {
        long long tmp = curVal;
        tmp += (long long) space * rng[r + 1][2];
        ans = max(ans, tmp); 
      }
      ans = max(ans, curVal);
      curLen -= len[l];
      curVal -= (long long) rng[l][2] * len[l];
    }    
    reverse(len.begin(), len.end());
    reverse(rng.begin(), rng.end());
  }
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 80 ms 16820 KB Output is correct
22 Correct 87 ms 20148 KB Output is correct
23 Correct 78 ms 19448 KB Output is correct
24 Correct 74 ms 19640 KB Output is correct
25 Correct 83 ms 19072 KB Output is correct
26 Correct 72 ms 17348 KB Output is correct
27 Correct 81 ms 20364 KB Output is correct
28 Correct 68 ms 18456 KB Output is correct
29 Correct 76 ms 16596 KB Output is correct