Submission #471561

#TimeUsernameProblemLanguageResultExecution timeMemory
471561CaroLindaPotatoes and fertilizers (LMIO19_bulves)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h>

#define debug 
#define ll long long

const int MAXN = 5e5+10 ;

using namespace std ;

int N ;
ll C[MAXN] , x , y ;
ll ans , p ;
priority_queue< ll > q ;

int main()
{
	scanf("%d", &N ) ;
	for(int i = 0 ; i < N ; i++ )
	{
		scanf("%lld %lld", &x, &y ) ;
		C[i] = x-y ;
		C[i] += C[i-1] ;
	}
	
	for(int i = 0 ; i < N ; i++ )
	{
		if(C[i] < 0 ) ans -= C[i] , C[i] = 0 ;
		if(C[i] > C[N-1] ) ans += C[i]-C[N-1] , C[i] = C[N-1] ;
								
		q.push(C[i]) ;
		q.push(C[i]) ;
		ans += abs(q.top()-C[i]) ;
		q.pop() ;
	}

	printf("%lld\n" , ans ) ;
	
}

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d", &N ) ;
      |  ~~~~~^~~~~~~~~~~
bulves.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%lld %lld", &x, &y ) ;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...