Submission #522196

#TimeUsernameProblemLanguageResultExecution timeMemory
522196bluePotatoes and fertilizers (LMIO19_bulves)C++17
24 / 100
270 ms14764 KiB
#include <iostream>
#include <vector>
using namespace std;

using ll = long long;
using vll = vector<ll>;

int main()
{
	int N;
	cin >> N;

	vll A(1+N), B(1+N);
	ll totA = 0, totB = 0;
	for(int i = 1; i <= N; i++) 
	{
		cin >> A[i] >> B[i];
		totA += A[i];
		totB += B[i];
	}

	A[0] = B[0] = 0;

	ll res = 0;

	ll currA = 0, currB = 0;

	for(int b = 1; b < N; b++)
	{
		currA += A[b];
		currB += B[b];

		if(currA < currB) res += currB - currA;
		if((totA - currA) < (totB - currB)) res += (totB - currB) - (totA - currA);
	}

	cout << res << '\n';
}
#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...