Submission #249435

#TimeUsernameProblemLanguageResultExecution timeMemory
249435jamielimCake 3 (JOI19_cake3)C++14
24 / 100
4086 ms5192 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	pll p[n];
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&p[i].se,&p[i].fi);
	}
	sort(p,p+n);
	ll ans=-LLINF;
	for(int i=0;i+m<=n;i++){
		priority_queue<ll,vector<ll>,greater<ll> > pq;
		ll sum=0;
		for(int j=i;j<i+m;j++){
			sum+=p[j].se;
			pq.push(p[j].se);
		}
		ans=max(ans,sum-2LL*(p[i+m-1].fi-p[i].fi));
		for(int j=i+m;j<n;j++){
			if(p[j].se>pq.top()){
				sum-=pq.top();sum+=p[j].se;
				pq.pop();pq.push(p[j].se);
			}
			ans=max(ans,sum-2LL*(p[j].fi-p[i].fi));
		}
	}
	printf("%lld",ans);
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
cake3.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&p[i].se,&p[i].fi);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...