Submission #586544

# Submission time Handle Problem Language Result Execution time Memory
586544 2022-06-30T11:33:23 Z MilosMilutinovic Autobahn (COI21_autobahn) C++14
0 / 100
1 ms 340 KB
/**
 *    author:  wxhtzdy
 *    created: 30.06.2022 13:02:32
**/
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k, x;
  cin >> n >> k >> x;
  vector<int> l(n), t(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> t[i] >> r[i];
    t[i] = min(t[i], r[i] - l[i] + 1);
  }
  vector<int> xs;
  for (int i = 0; i < n; i++) {
    xs.push_back(l[i]);
    xs.push_back(l[i] + t[i]);
    xs.push_back(r[i] + 1);    
  }       
  int m = (int) xs.size();
  for (int i = 0; i < m; i++) {
    xs.push_back(xs[i] + x);
    xs.push_back(xs[i] - x);    
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  m = (int) xs.size();
  vector<int> sa(m);
  vector<int> sb(m);
  auto Get = [&](int x) {
    return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
  };
  for (int i = 0; i < n; i++) {
    sa[Get(l[i])] += 1;  
    sa[Get(r[i] + 1)] -= 1;
    sb[Get(l[i] + t[i])] += 1;
    sb[Get(r[i] + 1)] -= 1;
  }
  for (int i = 1; i < m; i++) {
    sa[i] += sa[i - 1];
    sb[i] += sb[i - 1];
  }
  vector<long long> f(m);
  for (int i = 0; i < m - 1; i++) {
    long long d = xs[i + 1] - xs[i];
    f[i] = (i == 0 ? 0LL : f[i - 1]) + d * (sa[i] >= k ? sb[i] : 0);
  } 
  f[m - 1] = f[m - 2];
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    int j = Get(xs[i] + x - 1);
    if (j < m && xs[j] >= xs[i]) {
      ans = max(ans, f[j] - (i == 0 ? 0LL : f[i - 1]));
    }
  }
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -