답안 #693830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
693830 2023-02-03T09:32:01 Z 79brue Autobahn (COI21_autobahn) C++17
0 / 100
0 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

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

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

        cnt[lp]++, cnt[rp]--;
        sum[mp]++, sum[rp]--;
    }
    for(int 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] * (point[i+1] - point[i]);
        wsum[i] = (i ? wsum[i-1] : 0LL) + w[i];
    }

    int pnt = 0;
    for(int i=0; i<len; i++){
        while(pnt+1 < len && point[pnt+1] < point[i] + x) pnt++;
        ans = max(ans, wsum[pnt-1] - (i==0 ? 0 : wsum[i-1]) + (point[i] + x - point[pnt]) * sum[pnt]);
    }

    pnt = 0;
    for(int i=0; i<len; i++){
        while(point[pnt+1] <= point[i+1] - 1 - x) pnt++;
        if(pnt) ans = max(ans, wsum[i] - wsum[pnt] + (point[pnt+1] - (point[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("%d %d %d", &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("%d %d %d", &l[i], &t[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -