Submission #90510

#TimeUsernameProblemLanguageResultExecution timeMemory
90510daniel_02Divide and conquer (IZhO14_divide)C++14
100 / 100
58 ms24508 KiB
#include <bits/stdc++.h>

#define fr first
#define pb push_back
#define sc second
#define ll long long

using namespace std;

const int N = 1e5 + 7;;
const ll inf = 1e18 + 7;

pair<int, pair<int, int>> a[N];
ll pre[N], prg[N], ans;
ll t[N * 4];

void upd(int v, int tl, int tr, int pos)
{	
	if (tl == tr)
	{
		t[v] = pre[pos - 1] - a[pos].fr;
	}
	else
	{
		int mid = (tl + tr) >> 1;
		
		if (mid >= pos)
			upd(v + v, tl, mid, pos);
		else
			upd(v + v + 1, mid + 1, tr, pos);
			
		t[v] = min(t[v + v], t[v + v + 1]);
	}
}
int get(int v, int tl, int tr, int pos)
{
	if (tl == tr)
	{
		return tl;
	}
	else
	{
		int mid = (tl + tr) >> 1;
		
		if (t[v + v] <= pre[pos] - a[pos].fr)
			return get(v + v, tl, mid, pos);
		else
			return get(v + v + 1, mid + 1, tr, pos);
	}
}
main()
{
	int n;
	
	cin >> n;
	
	for (int i = 0; i < N * 4; i++)
		t[i] = inf;
	
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d%d", &a[i].fr, &a[i].sc.fr, &a[i].sc.sc);
		pre[i] = pre[i - 1] + a[i].sc.sc;
		prg[i] = prg[i - 1] + a[i].sc.fr;
	}
	
	for (int i = 1; i <= n; i++)
	{
		upd(1, 1, n, i);
		ans = max(ans, prg[i] - prg[get(1, 1, n, i) - 1]);
	}
	cout << ans;
}

Compilation message (stderr)

divide.cpp:51:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
divide.cpp: In function 'int main()':
divide.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a[i].fr, &a[i].sc.fr, &a[i].sc.sc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...