이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define SURE 2.0
#define mod 1000000007
#define inf 1000000000000000009
#define N 200005
using namespace std;
typedef long long ll;
typedef pair < int , int > ii;
int n, m, k, bas = 1, son, amk, a[N], b[N], ne[N], say[4*N];
ll seg[4*N], of, cvp, opt, ans = -inf, ek;
ii xx[N];
map < int , int > h, x;
map < int , int > :: iterator it;
vector < int > g[N];
void bitir(){
printf("%lld\n", ans);
exit(0);
}
void bu(int k, int bas, int son, int x){
g[x].pb(k);
if(bas == son)
return;
if(x <= orta)
bu(sol, bas, orta, x);
else
bu(sag, orta + 1, son, x);
}
void up(int x, int y){
int sz = g[x].size();
ek = 1ll*y*ne[x];
for(int i = 0; i < sz; i++){
seg[g[x][i]] += ek;
say[g[x][i]] += y;
}
}
ll qu(int k, int bas, int son, int x){
if(bas == son)
return 1ll*x*ne[bas];
if(say[sag] >= x)
return qu(sag, orta + 1, son, x);
return seg[sag] + qu(sol, bas, orta, x - say[sag]);
}
void getir(int bs, int sn){
while(bas < bs){
up(a[bas], -1);
bas++;
}
while(bas > bs){
bas--;
up(a[bas], 1);
}
while(son > sn){
up(a[son], -1);
son--;
}
while(son < sn){
son++;
up(a[son], 1);
}
}
void f(int bas, int son, int optl, int optr){
// amk++;if(amk > 50)exit(0);
if(bas > son or optr - bas + 1 < m)return;
int optm = optr;
opt = -inf;
for(int i = max(m + orta - 1, optl); i <= optr; i++){
getir(orta + 1, i - 1);
of = qu(1, 1, k, m - 2);
cvp = of + 1ll*ne[a[orta]] + 1ll*ne[a[i]] - 2ll*(b[i] - b[orta]);
// if(cvp == 152)cout << "geldi amk " << orta << " " << i << " " << of << " = " << cvp << endl;
if(cvp > opt){
opt = cvp;
optm = i;
}
}
// cout << bas << " " << son << " " << orta << " " << optl << " " << optr << " = " << opt << " " << optm << endl;
ans = max(ans, opt);
f(bas, orta - 1, optl, optm);
f(orta + 1, son, optm, optr);
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d",&n ,&m);
for(int i = 1; i <= n; i++){
scanf("%d %d",&xx[i].nd ,&xx[i].st);
h[xx[i].nd]++;
}
for(it = h.begin(); it != h.end(); it++){
x[it->st] = ++k;
ne[k] = it->st;
// cout << k << " " << it->st << endl;
}
sort(xx + 1, xx + n + 1);
for(int i = 1; i <= n; i++){
a[i] = x[xx[i].nd];
b[i] = xx[i].st;
// cout << a[i] << " " << b[i] << endl;;
}
for(int i = 1; i <= k; i++)
bu(1, 1, k, i);
f(1, n, m, n);
printf("%lld\n", ans);
// cout << amk << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp: In function 'int main()':
cake3.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n ,&m);
~~~~~^~~~~~~~~~~~~~~~
cake3.cpp:103:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&xx[i].nd ,&xx[i].st);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |