Submission #213085

#TimeUsernameProblemLanguageResultExecution timeMemory
213085YJUCake 3 (JOI19_cake3)C++14
0 / 100
18 ms384 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll MOD=1e9+7; const ll N=2e5+5; const ld pi=3.14159265359; const ll INF=(1LL<<62); #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(a) (ll)a.size() ll n,m,val[N],c[N],tmp,ans; vector<ll> v; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; REP(i,n)cin>>val[i]>>c[i]; REP(i,n){ REP(j,n){ if(i==j)continue; v.clear();tmp=0; REP(k,n){ if(k==i||k==j)continue; if(c[k]>=min(c[i],c[j])&&c[k]<=max(c[i],c[j]))v.pb(val[k]); } if(SZ(v)<m-2)continue; sort(v.rbegin(),v.rend()); REP(k,m-2)tmp+=v[k]; ans=max(ans,val[i]+val[j]+tmp-2*abs(c[i]-c[j])); } } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...