# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
376679 | daniel920712 | Cake 3 (JOI19_cake3) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
pair < long long , long long > all[200005];
long long pre[200005]={0};
vector < long long > tt;
bool cmp(long long a,long long b)
{
return a>b;
}
int main()
{
long long N,M,ans=0,i,j,k,xx=0;
scanf("%lld %lld",&N,&M);
for(i=1;i<=N;i++)
{
scanf("%lld %lld",&all[i].second,&all[i].first);
}
sort(all+1,all+N+1);
//for(i=1;i<=N;i++) pre[i]=pre[i-1]+all[i].second;
for(i=1;i<=N;i++)
{
tt.clear();
for(j=i;j<=N;j++)
{
tt.push_back(all[j].second);
if(j-i+1>=M)
{
xx=0;
sort(tt.begin(),tt.end(),cmp);
for(k=0;k<M;k++) xx+=tt[k];
xx-=2*(all[j].first-all[i].first);
ans=max(ans,xx);
}
}
}
printf("%lld\n",ans);
return 0;
}