이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "cake3"
#define all(a) a.begin(),a.end()
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 2e5 + 9;
int n,m,a[MAXN],ans=INF;
ii p[MAXN];
struct Info{
int cnt=0,sum=0;
};
Info st[MAXN<<2];
vector<int> listval;
void update(int node,int l,int r,int pos,int val){
if (l==r){
st[node].cnt += val;
st[node].sum = listval[l-1] * st[node].cnt;
return;
}
int mid = (l+r)>>1;
if (pos<=mid) update(node<<1,l,mid,pos,val);
else update(node<<1|1,mid+1,r,pos,val);
st[node].cnt = st[node<<1].cnt + st[node<<1|1].cnt;
st[node].sum = st[node<<1].sum + st[node<<1|1].sum;
}
int getkth(int node,int l,int r,int k){
if (l==r){
return k * listval[l-1];
}
int mid = (l+r)>>1;
if (st[node<<1|1].cnt >= k) return getkth(node<<1|1,mid+1,r,k);
else return st[node<<1|1].sum + getkth(node<<1,l,mid,k-st[node<<1|1].cnt);
}
int getval(int x){
return lower_bound(all(listval),x) - listval.begin() + 1;
}
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>p[i].fi>>p[i].se;
listval.pb(p[i].fi);
}
sort(listval.begin(),listval.end());
listval.erase(unique(all(listval)),listval.end());
sort(p+1,p+1+n,[](const ii &a,const ii &b){
return a.se < b.se;
});
int ans = -INF;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
if (j-i+1 >= m){
int cur = p[i].fi + p[j].fi + getkth(1,1,sz(listval),m-2) - (p[j].se - p[i].se) * 2;
maximize(ans, cur);
}
if (j>i) {
update(1,1,sz(listval),getval(p[j].fi),1);
}
}
for(int j=i+1;j<=n;j++){
update(1,1,sz(listval),getval(p[j].fi),-1);
}
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
cake3.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main()
| ^~~~
cake3.cpp: In function 'int main()':
cake3.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |