이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
multiset<ll>st;
pair<ll,ll>a[200005];
ll n,m,ans=-9999999999999999;
void solve(ll l,ll r,ll x,ll y){
l = max(l , x + m - 1);
if(l > r)return;
ll k = (l + r) / 2;
ll mx = -9999999999999999 , ind = y;
st.clear();
ll cur = 0;
for(int i=k; i>=x; i--){
ll mn = 0;
if(st.size())mn = (*st.begin());
if(mn < a[i].s || ((int)st.size() < m)){
cur += a[i].s;
if(st.size() >= m){st.erase(st.begin());cur -= mn;}
st.insert(a[i].s);
}
if(st.size() >= m && cur - 2 * (a[k].f - a[i].f) > mx)
mx = cur - 2 * (a[k].f - a[i].f),
ind = i;
}
if(mx == -9999999999999999)return;
ans = max(ans , mx);
if(l == r)return;
solve(l , k , x , ind);
solve(k + 1 , r , ind , y);
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> a[i].s >> a[i].f;
}
sort(a + 1 , a + n + 1);
solve(1 , n , 1 , n);
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'void solve(long long int, long long int, long long int, long long int)':
cake3.cpp:22:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(st.size() >= m){st.erase(st.begin());cur -= mn;}
~~~~~~~~~~^~~~
cake3.cpp:25:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(st.size() >= m && cur - 2 * (a[k].f - a[i].f) > mx)
~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |