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 <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 110;
pll arr[mxn];
int N,K;
ll calc(ll l,ll r){
vector<ll> v;
for(int i = l+1;i<r;i++)v.push_back(arr[i].sc);
sort(v.rbegin(),v.rend());
ll re = arr[l].sc+arr[r].sc-arr[r].fs*2+arr[l].fs*2;
for(int i = 0;i<K-2;i++)re += v[i];
return re;
}
main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>K;
for(int i = 1;i<=N;i++)cin>>arr[i].sc>>arr[i].fs;
sort(arr+1,arr+N+1);
ll ans = -1e18;
for(int i = 1;i<=N;i++){
for(int j = i+K-1;j<=N;j++)ans = max(ans,calc(i,j));
}
cout<<ans<<'\n';
}
Compilation message (stderr)
cake3.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |