이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, x, len;
ll l[300002], t[300002], r[300002];
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("%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]++;
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 = (ll)point.size();
for(ll i=1; i<=n; i++){
ll lp = lower_bound(point.begin(), point.end(), l[i]) - point.begin();
ll mp = lower_bound(point.begin(), point.end(), min(r[i], l[i] + t[i])) - point.begin();
ll rp = lower_bound(point.begin(), point.end(), r[i]) - point.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];
}
for(ll i=0; i<len-1; i++){
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];
}
ll pnt;
for(ll i=1; i<len; i++){
pnt = upper_bound(point.begin(), point.end(), point[i] + x - 1) - 1 - point.begin();
ans = max(ans, wsum[pnt-1] - wsum[i-1] + (point[i] + x - point[pnt]) * sum[pnt]);
}
for(ll i=0; i<len-1; i++){
pnt = upper_bound(point.begin(), point.end(), point[i+1] - x) - 1 - point.begin();
if(pnt) ans = max(ans, wsum[i] - wsum[pnt] + (point[pnt+1] - (point[i+1] - x)) * sum[pnt]);
}
printf("%lld", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
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:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%lld %lld %lld", &l[i], &t[i], &r[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |