# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376680 | daniel920712 | Cake 3 (JOI19_cake3) | C++14 | 4 ms | 380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <utility>
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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |