Submission #275580

# Submission time Handle Problem Language Result Execution time Memory
275580 2020-08-20T06:35:33 Z 최은수(#5098) Radio (Balkan15_RADIO) C++17
75 / 100
1547 ms 18168 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;
pl operator+(pl x,pl y)
{
    return pl(x.fi+y.fi,x.se+y.se);
}
ll x[100010],p[100010],s[100010];
int n;
pl get(ll bnd)
{
    pl cur(0,0);
    ll ccnt=0;
    vector<pair<pl,pl> >cv;
    int ct=0;
    for(int i=0;i++<n;)
        if(s[i]<bnd)
            ct+=s[i]==bnd-1?2:4;
    cv.reserve(ct);
    for(int i=0;i++<n;)
    {
        cur.se+=bnd;
        if(s[i]<bnd)
        {
            if(s[i]==bnd-1)
            {
                cv.eb(pl(x[i]-p[i],1),pl(0,-1));
                cv.eb(pl(x[i]+p[i]+1,-1),pl(0,1));
            }
            else
            {
                cv.eb(pl(x[i]-p[i]-(bnd-s[i])+1,1),pl(-1,x[i]-p[i]-(bnd-s[i])));
                cv.eb(pl(x[i]-p[i],0),pl(1,-(x[i]-p[i])));
                cv.eb(pl(x[i]+p[i],0),pl(1,-(x[i]+p[i])));
                cv.eb(pl(x[i]+p[i]+(bnd-s[i]),-1),pl(-1,x[i]+p[i]+(bnd-s[i])));
            }
        }
    }
    pl 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,pl(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;
    for(int i=0;i++<n;)
        cin>>x[i]>>p[i]>>s[i];
    if(n<=1000)
    {
        vector<ll>lst;
        for(int i=0;i++<n;)
            lst.eb(x[i]-p[i]),lst.eb(x[i]+p[i]);
        sort(all(lst));
        lst.erase(unique(all(lst)),lst.end());
        ll ans=INF;
        ll all=0;
        for(int i=0;i++<n;)
            all+=s[i];
        for(ll&t:lst)
        {
            vector<ll>cost;
            for(int i=0;i++<n;)
                cost.eb(max(abs(t-x[i])-p[i],0ll)+s[i]);
            sort(all(cost));
            ll cc=0;
            for(int i=0;i<k;i++)
                cc+=cost[i];
            ans=min(ans,cc-all);
        }
        cout<<ans<<endl;
        return 0;
    }
    ll cs=1,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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 75 ms 384 KB Output is correct
5 Correct 117 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 37 ms 384 KB Output is correct
5 Correct 51 ms 384 KB Output is correct
6 Correct 70 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 75 ms 384 KB Output is correct
5 Correct 117 ms 512 KB Output is correct
6 Correct 64 ms 1292 KB Output is correct
7 Correct 256 ms 3856 KB Output is correct
8 Correct 632 ms 9076 KB Output is correct
9 Correct 1234 ms 14228 KB Output is correct
10 Correct 1332 ms 16764 KB Output is correct
11 Correct 1547 ms 17276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 37 ms 384 KB Output is correct
5 Correct 51 ms 384 KB Output is correct
6 Correct 70 ms 512 KB Output is correct
7 Correct 62 ms 1164 KB Output is correct
8 Correct 254 ms 4224 KB Output is correct
9 Correct 640 ms 8724 KB Output is correct
10 Correct 1074 ms 13308 KB Output is correct
11 Correct 796 ms 11396 KB Output is correct
12 Correct 1424 ms 17236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 75 ms 384 KB Output is correct
12 Correct 117 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 11 ms 384 KB Output is correct
16 Correct 37 ms 384 KB Output is correct
17 Correct 51 ms 384 KB Output is correct
18 Correct 70 ms 512 KB Output is correct
19 Correct 64 ms 1292 KB Output is correct
20 Correct 256 ms 3856 KB Output is correct
21 Correct 632 ms 9076 KB Output is correct
22 Correct 1234 ms 14228 KB Output is correct
23 Correct 1332 ms 16764 KB Output is correct
24 Correct 1547 ms 17276 KB Output is correct
25 Correct 62 ms 1164 KB Output is correct
26 Correct 254 ms 4224 KB Output is correct
27 Correct 640 ms 8724 KB Output is correct
28 Correct 1074 ms 13308 KB Output is correct
29 Correct 796 ms 11396 KB Output is correct
30 Correct 1424 ms 17236 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 362 ms 5504 KB Output is correct
33 Correct 509 ms 7552 KB Output is correct
34 Correct 355 ms 9344 KB Output is correct
35 Correct 658 ms 11500 KB Output is correct
36 Correct 749 ms 18168 KB Output is correct
37 Correct 1299 ms 17304 KB Output is correct
38 Correct 1360 ms 17144 KB Output is correct
39 Incorrect 916 ms 17140 KB Output isn't correct
40 Halted 0 ms 0 KB -