Submission #285140

#TimeUsernameProblemLanguageResultExecution timeMemory
285140PyqePotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
228 ms15336 KiB
#include <bits/stdc++.h>

using namespace std;

long long n,ps[500069];
priority_queue<long long> pq;

int main()
{
	long long i,ii,k,l,z=0;
	
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld%lld",&k,&l);
		ps[i]=ps[i-1]+k-l;
	}
	for(i=1;i<n;i++)
	{
		k=min(max(ps[i],0ll),ps[n]);
		z+=abs(k-ps[i]);
		ps[i]=k;
		if(i-1)
		{
			z+=max(pq.top()-ps[i],0ll);
		}
		for(ii=0;ii<2;ii++)
		{
			pq.push(ps[i]);
		}
		pq.pop();
	}
	printf("%lld\n",z);
}

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
bulves.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   scanf("%lld%lld",&k,&l);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...