Submission #340500

# Submission time Handle Problem Language Result Execution time Memory
340500 2020-12-27T19:12:31 Z ogibogi2004 Radio (Balkan15_RADIO) C++14
100 / 100
1110 ms 47340 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=1e5+6;
const ll INF=2e15;
struct event
{
	ll pos;
	bool f;
};
struct tower
{
	ll l,r;
	ll s,pos;
	bool operator<(tower const& other)const
	{
		if(s-r!=other.s-other.r)return s-r<other.s-other.r;
		else return pos<other.pos;
	}
}t[MAXN];
///change cmp functions then do "xd"
bool cmpl(tower t1,tower t2)
{
	if(t1.s-t1.r!=t2.s-t2.r)return t1.s-t1.r<t2.s-t2.r;
	return t1.pos<t2.pos;
}
bool cmpr(tower t1,tower t2)
{
	if(t1.s+t1.l!=t2.s+t2.l)return t1.s+t1.l<t2.s+t2.l;
	return t1.pos<t2.pos;
}
bool cmpm(tower t1,tower t2)
{
	if(t1.s!=t2.s)return t1.s<t2.s;
	return t1.pos<t2.pos;
}
string status[MAXN];
set<tower,decltype(cmpl)*>LeftActive(cmpl);
set<tower,decltype(cmpr)*>RightActive(cmpr);
set<tower,decltype(cmpm)*>MiddleActive(cmpm);
set<tower,decltype(cmpl)*>LeftUnactive(cmpl);
set<tower,decltype(cmpr)*>RightUnactive(cmpr);
set<tower,decltype(cmpm)*>MiddleUnactive(cmpm);
map<ll,vector<event> >sweep_line;
int main()
{
	ll n,k;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	{
		ll x,p,s;
		cin>>x>>p>>s;
		t[i].l=x-p;
		t[i].r=x+p;
		t[i].s=s;
		t[i].pos=i;
		if(!sweep_line.count(x))
		{
			sweep_line[x]={};
		}
		sweep_line[t[i].l].push_back({i,1});
		sweep_line[t[i].r].push_back({i,0});
		RightUnactive.insert(t[i]);
		status[i]="RU";
	}
	ll total_win=0,ans=-INF,last=-INF;
	for(ll i=1;i<=n;i++)total_win+=t[i].s;
	for(auto line:sweep_line)
	{
		total_win-=(LeftActive.size()-RightActive.size())*(line.first-last);
		//cout<<line.first<<":\n";
		vector<tower>v0,v1;
		for(auto l:line.second)
		{
			if(l.f==0)v0.push_back(t[l.pos]);
			else v1.push_back(t[l.pos]);
		}
		//cout<<"*1*\n";
		for(auto v:v1)
		{
			if(status[v.pos]=="RU")
			{
				RightUnactive.erase(t[v.pos]);
				MiddleUnactive.insert(t[v.pos]);
				status[v.pos]="MU";
			}
			else if(status[v.pos]=="RA")
			{
				RightActive.erase(t[v.pos]);
				MiddleActive.insert(t[v.pos]);
				status[v.pos]="MA";
			}
		}
		//cout<<"*2*\n";
		for(auto v:v0)
		{
			if(status[v.pos]=="MA")
			{
				MiddleActive.erase(t[v.pos]);
				LeftActive.insert(t[v.pos]);
				status[v.pos]="LA";
			}
			if(status[v.pos]=="MU")
			{
				MiddleUnactive.erase(t[v.pos]);
				LeftUnactive.insert(t[v.pos]);
				status[v.pos]="LU";
			}
		}
		//cout<<"*3*\n";
		while(LeftActive.size()+RightActive.size()+MiddleActive.size()<k)
		{
			//cout<<LeftActive.size()+RightActive.size()+MiddleActive.size()<<endl;
			//cout<<"*"<<LeftUnactive.size()<<" "<<MiddleUnactive.size()<<" "<<RightUnactive.size()<<endl;
			//cout<<total_win<<endl;
			if(LeftUnactive.size()+MiddleUnactive.size()+RightUnactive.size()==0)break;
			pair<pair<ll,tower>,string>leu;
			leu={{INF,{0ll,0ll,0ll}},"no"};
			ll cost;
			if(LeftUnactive.size()!=0)
			{
				auto f=(*LeftUnactive.begin());
				cost=f.s+line.first-f.r;
				leu=min(leu,{{cost,f},"LU"});
			}
			if(MiddleUnactive.size()!=0)
			{
				auto f=(*MiddleUnactive.begin());
				cost=f.s;
				leu=min(leu,{{cost,f},"MU"});
			}
			if(RightUnactive.size()!=0)
			{
				auto f=(*RightUnactive.begin());
				cost=f.s+f.l-line.first;
				leu=min(leu,{{cost,f},"RU"});
			}
			//cout<<"^"<<leu.first.first<<endl;
			total_win-=leu.first.first;
			if(status[leu.first.second.pos]=="LU")
			{
				LeftUnactive.erase(leu.first.second);
				LeftActive.insert(leu.first.second);
				status[leu.first.second.pos]="LA";
			}
			else if(status[leu.first.second.pos]=="MU")
			{
				MiddleUnactive.erase(leu.first.second);
				MiddleActive.insert(leu.first.second);
				status[leu.first.second.pos]="MA";
			}
			else if(status[leu.first.second.pos]=="RU")
			{
				RightUnactive.erase(leu.first.second);
				RightActive.insert(leu.first.second);
				status[leu.first.second.pos]="RA";
			}
		}
		//cout<<"*4*\n";
		for(;;)
		{
			//cout<<LeftActive.size()+MiddleActive.size()+RightActive.size()<<" "<<k<<endl;
			//cout<<LeftActive.size()<<" "<<LeftUnactive.size()<<" "<<MiddleActive.size()<<" "<<MiddleUnactive.size()<<" "<<RightActive.size()<<" "<<RightUnactive.size()<<endl;
			pair<pair<ll,tower>,string>mea,leu;
			mea={{(ll)-1,{0ll,0ll,0ll}},"no"};
			leu={{INF,{0ll,0ll,0ll}},"no"};
			ll cost;
			if(LeftUnactive.size()!=0)
			{
				auto f=(*LeftUnactive.begin());
				cost=f.s+line.first-f.r;
				leu=min(leu,{{cost,f},"LU"});
			}
			if(MiddleUnactive.size()!=0)
			{
				auto f=(*MiddleUnactive.begin());
				cost=f.s;
				leu=min(leu,{{cost,f},"MU"});
			}
			if(RightUnactive.size()!=0)
			{
				auto f=(*RightUnactive.begin());
				cost=f.s+f.l-line.first;
				leu=min(leu,{{cost,f},"RU"});
			}
			if(LeftActive.size()!=0)
			{
				auto it=LeftActive.end();
				it--;
				auto f=(*it);
				cost=f.s+line.first-f.r;
				mea=max(mea,{{cost,f},"LA"});
			}
			if(MiddleActive.size()!=0)
			{
				auto it=MiddleActive.end();
				it--;
				auto f=(*it);
				cost=f.s;
				mea=max(mea,{{cost,f},"MA"});
			}
			if(RightActive.size()!=0)
			{
				auto it=RightActive.end();
				it--;
				auto f=(*it);
				cost=f.s+f.l-line.first;
				mea=max(mea,{{cost,f},"RA"});
			}
			//cout<<mea.first.first<<" "<<leu.first.first<<endl;
			if(mea.first.first<=leu.first.first)
			{
				break;
			}
			total_win+=mea.first.first;
			total_win-=leu.first.first;
			if(status[leu.first.second.pos]=="LU")
			{
				LeftUnactive.erase(leu.first.second);
				LeftActive.insert(leu.first.second);
				status[leu.first.second.pos]="LA";
			}
			else if(status[leu.first.second.pos]=="MU")
			{
				MiddleUnactive.erase(leu.first.second);
				MiddleActive.insert(leu.first.second);
				status[leu.first.second.pos]="MA";
			}
			else if(status[leu.first.second.pos]=="RU")
			{
				RightUnactive.erase(leu.first.second);
				RightActive.insert(leu.first.second);
				status[leu.first.second.pos]="RA";
			}
			if(status[mea.first.second.pos]=="LA")
			{
				LeftActive.erase(mea.first.second);
				LeftUnactive.insert(mea.first.second);
				status[mea.first.second.pos]="LU";
			}
			else if(status[mea.first.second.pos]=="MA")
			{
				MiddleActive.erase(mea.first.second);
				MiddleUnactive.insert(mea.first.second);
				status[mea.first.second.pos]="MU";
			}
			else if(status[mea.first.second.pos]=="RA")
			{
				RightActive.erase(mea.first.second);
				RightUnactive.insert(mea.first.second);
				status[mea.first.second.pos]="RU";
			}
		}
		//cout<<"*5*\n";
		ans=max(ans,total_win);
		//cout<<total_win<<endl;
		last=line.first;
	}
	cout<<-ans<<endl;
return 0;
}

Compilation message

radio.cpp: In function 'int main()':
radio.cpp:111:65: warning: comparison of integer expressions of different signedness: 'std::set<tower, bool (*)(tower, tower)>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  111 |   while(LeftActive.size()+RightActive.size()+MiddleActive.size()<k)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 2 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 2 ms 3436 KB Output is correct
7 Correct 2 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3564 KB Output is correct
3 Correct 4 ms 3692 KB Output is correct
4 Correct 7 ms 3820 KB Output is correct
5 Correct 7 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 3 ms 3564 KB Output is correct
3 Correct 5 ms 3712 KB Output is correct
4 Correct 5 ms 3820 KB Output is correct
5 Correct 5 ms 3820 KB Output is correct
6 Correct 6 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 3 ms 3564 KB Output is correct
3 Correct 4 ms 3692 KB Output is correct
4 Correct 7 ms 3820 KB Output is correct
5 Correct 7 ms 3948 KB Output is correct
6 Correct 30 ms 5612 KB Output is correct
7 Correct 97 ms 10604 KB Output is correct
8 Correct 251 ms 22124 KB Output is correct
9 Correct 815 ms 38636 KB Output is correct
10 Correct 392 ms 34056 KB Output is correct
11 Correct 1049 ms 47212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 3 ms 3564 KB Output is correct
3 Correct 5 ms 3712 KB Output is correct
4 Correct 5 ms 3820 KB Output is correct
5 Correct 5 ms 3820 KB Output is correct
6 Correct 6 ms 3948 KB Output is correct
7 Correct 28 ms 5612 KB Output is correct
8 Correct 97 ms 12908 KB Output is correct
9 Correct 242 ms 21996 KB Output is correct
10 Correct 470 ms 33832 KB Output is correct
11 Correct 281 ms 29548 KB Output is correct
12 Correct 882 ms 46444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 2 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 2 ms 3436 KB Output is correct
7 Correct 2 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 3 ms 3564 KB Output is correct
10 Correct 4 ms 3692 KB Output is correct
11 Correct 7 ms 3820 KB Output is correct
12 Correct 7 ms 3948 KB Output is correct
13 Correct 2 ms 3436 KB Output is correct
14 Correct 3 ms 3564 KB Output is correct
15 Correct 5 ms 3712 KB Output is correct
16 Correct 5 ms 3820 KB Output is correct
17 Correct 5 ms 3820 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 30 ms 5612 KB Output is correct
20 Correct 97 ms 10604 KB Output is correct
21 Correct 251 ms 22124 KB Output is correct
22 Correct 815 ms 38636 KB Output is correct
23 Correct 392 ms 34056 KB Output is correct
24 Correct 1049 ms 47212 KB Output is correct
25 Correct 28 ms 5612 KB Output is correct
26 Correct 97 ms 12908 KB Output is correct
27 Correct 242 ms 21996 KB Output is correct
28 Correct 470 ms 33832 KB Output is correct
29 Correct 281 ms 29548 KB Output is correct
30 Correct 882 ms 46444 KB Output is correct
31 Correct 2 ms 3436 KB Output is correct
32 Correct 165 ms 15416 KB Output is correct
33 Correct 210 ms 19180 KB Output is correct
34 Correct 475 ms 25580 KB Output is correct
35 Correct 310 ms 29548 KB Output is correct
36 Correct 1110 ms 47340 KB Output is correct
37 Correct 708 ms 42860 KB Output is correct
38 Correct 500 ms 44780 KB Output is correct
39 Correct 443 ms 38252 KB Output is correct
40 Correct 543 ms 40428 KB Output is correct