Submission #384151

#TimeUsernameProblemLanguageResultExecution timeMemory
384151LucaDantasPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
194 ms15340 KiB
#include <cstdio>
#include <queue>

std::priority_queue<long long> q;

int main() {
	int n; scanf("%d", &n);
	long long d[n+1]{}, ans = 0;
	for(int i = 1; i <= n; i++) {
		int a, b; scanf("%d %d", &a, &b);
		d[i] = d[i-1] + a - b;
	}
	for(int i = 1; i <= n; i++) {
		if(d[i] < 0) ans -= d[i], d[i] = 0;
		else if(d[i] > d[n]) ans += d[i] - d[n], d[i] = d[n];
		q.push(d[i]);
		if(d[i] < q.top()) ans += q.top() - d[i], q.pop(), q.push(d[i]);
	}
	printf("%lld\n", ans);
}

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:7:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
bulves.cpp:10:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |   int a, b; scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
#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...