# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
275509 |
2020-08-20T06:20:23 Z |
최은수(#5098) |
Radio (Balkan15_RADIO) |
C++17 |
|
1 ms |
384 KB |
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
pair<int,ll>operator+(pair<int,ll>x,pair<int,ll>y)
{
return pair<int,ll>(x.fi+y.fi,x.se+y.se);
}
ll x[100010],p[100010],s[100010];
int n;
pair<ll,int>get(int bnd)
{
pair<int,ll>cur(0,0);
int ccnt=0;
vector<pair<pair<ll,int>,pair<int,ll> > >cv;
int ct=0;
for(int i=0;i++<n;)
{
if(s[i]<bnd)
{
ct+=4;
if(s[i]==bnd-1)
ct-=2;
}
}
cv.reserve(ct);
for(int i=0;i++<n;)
{
cur.se+=bnd;
if(s[i]<bnd)
{
if(s[i]==bnd-1)
{
cv.eb(pair<ll,int>(x[i]-p[i],1),pair<int,ll>(0,-1));
cv.eb(pair<ll,int>(x[i]+p[i]+1,-1),pair<int,ll>(0,1));
}
else
{
cv.eb(pair<ll,int>(x[i]-p[i]-(bnd-s[i])+1,1),pair<int,ll>(-1,x[i]-p[i]-(bnd-s[i])));
cv.eb(pair<ll,int>(x[i]-p[i],0),pair<int,ll>(1,-(x[i]-p[i])));
cv.eb(pair<ll,int>(x[i]+p[i],0),pair<int,ll>(1,-(x[i]+p[i])));
cv.eb(pair<ll,int>(x[i]+p[i]+(bnd-s[i]),-1),pair<int,ll>(-1,x[i]+p[i]+(bnd-s[i])));
}
}
}
pair<ll,int>mn(bnd*n,0);
sort(all(cv));
for(int i=0;i<(int)cv.size();i++)
{
auto&t=cv[i];
cur=cur+t.se;
ccnt+=t.fi.se;
if(i==(int)cv.size()-1||cv[i].fi.fi!=cv[i+1].fi.fi)
mn=min(mn,pair<ll,int>(cur.fi*t.fi.fi+cur.se,ccnt));
}
return mn;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int k;
cin>>n>>k;
vector<ll>lst;
for(int i=0;i++<n;)
cin>>x[i]>>p[i]>>s[i];
ll cs=0;
ll ce=2e9;
while(cs<ce)
{
ll cm=cs+(ce-cs+1)/2;
pl cur=get(cm);
if(cur.se>k)
ce=cm-1;
else
cs=cm;
}
ll ans=get(cs).fi-cs*(n-k);
for(int i=0;i++<n;)
ans-=s[i];
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |