Submission #693835

# Submission time Handle Problem Language Result Execution time Memory
693835 2023-02-03T09:40:42 Z 79brue Autobahn (COI21_autobahn) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n, k, x, len;
ll l[100002], t[100002], r[100002];
vector<ll> poll = {-1'000'000'000, 1'000'000'000};
ll cnt[300002], sum[300002], w[300002], wsum[300002]; /// 사람 수, 벌금 사람 수
ll ans;

int main(){
    scanf("%lld %lld %lld", &n, &k, &x);
    for(ll i=1; i<=n; i++){
        scanf("%lld %lld %lld", &l[i], &t[i], &r[i]);
        r[i]++;
        poll.push_back(l[i]), poll.push_back(r[i]);
        if(l[i] + t[i] < r[i]) poll.push_back(l[i] + t[i]);
    }
    sort(poll.begin(), poll.end());
    poll.erase(unique(poll.begin(), poll.end()), poll.end());
    len = (ll)poll.size();

    for(ll i=1; i<=n; i++){
        ll lp = lower_bound(poll.begin(), poll.end(), l[i]) - poll.begin();
        ll mp = lower_bound(poll.begin(), poll.end(), min(r[i], l[i] + t[i])) - poll.begin();
        ll rp = lower_bound(poll.begin(), poll.end(), r[i]) - poll.begin();

        cnt[lp]++, cnt[rp]--;
        sum[mp]++, sum[rp]--;
    }
    for(ll i=0; i<len-1; i++){
        if(i) cnt[i] += cnt[i-1], sum[i] += sum[i-1];
        if(cnt[i] < k) sum[i] = 0;
        w[i] = sum[i] * (poll[i+1] - poll[i]);
        wsum[i] = (i ? wsum[i-1] : 0LL) + w[i];
    }

    ll pnt;
    for(ll i=1; i<len; i++){
        pnt = upper_bound(poll.begin(), poll.end(), poll[i] + x - 1) - 1 - poll.begin();
        ans = max(ans, wsum[pnt-1] - wsum[i-1] + (poll[i] + x - poll[pnt]) * sum[pnt]);
    }

    for(ll i=0; i<len-1; i++){
        pnt = upper_bound(poll.begin(), poll.end(), poll[i+1] - x) - 1 - poll.begin();
        if(pnt) ans = max(ans, wsum[i] - wsum[pnt] + (poll[pnt+1] - (poll[i+1] - x)) * sum[pnt]);
    }

    printf("%lld", ans);
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld %lld %lld", &n, &k, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
autobahn.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld %lld %lld", &l[i], &t[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -