Submission #122174

#TimeUsernameProblemLanguageResultExecution timeMemory
122174dualityCake 3 (JOI19_cake3)C++11
5 / 100
4038 ms476 KiB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

pii cake[200000];
LLI query(int s,int e,int M) {
    if (e-s+1 < M) return -1e18;
    else {
        int i;
        LLI ans = 0;
        vi v;
        for (i = s; i <= e; i++) v.pb(cake[i].second);
        sort(v.begin(),v.end(),greater<int>());
        for (i = 0; i < M; i++) ans += v[i];
        return ans-2*(cake[e].first-cake[s].first);
    }
}
LLI ans = -1e18;
int solve(int l,int r,int al,int ar,int M) {
    if (l > r) return 0;
    int i,m = (l+r) / 2,b = al;
    LLI best = -1e18;
    for (i = al; i <= ar; i++) {
        LLI x = query(m,i,M);
        if (x > best) best = x,b = i;
    }
    ans = max(ans,best);
    solve(l,m-1,al,min(b+100,ar),M),solve(m+1,r,max(b-100,al),ar,M);
    return 0;
}
int main() {
    int i;
    int N,M;
    scanf("%d %d",&N,&M);
    for (i = 0; i < N; i++) scanf("%d %d",&cake[i].second,&cake[i].first);
    sort(cake,cake+N);
    solve(0,N-1,0,N-1,M);
    /*

    int j;
    LLI ans = -1e18;
    int p = 0;
    for (i = 0; i <= N-M; i++) {
        LLI sum = 0;
        for (j = i; j < i+M; j++) H.push(cake[j].second),sum += cake[j].second;
        LLI best = sum-2*(cake[i+M-1].first-cake[i].first);
        int pos = i+M-1;
        for (j = i+M; j < N; j++) {
            H.push(cake[j].second),sum += cake[j].second;
            sum -= H.top(),H.pop();
            LLI x = sum-2*(cake[j].first-cake[i].first);
            if (x > best) best = x,pos = j;
        }
        while (!H.empty()) H.pop();
        ans = max(ans,best);
        if (pos < p) return -1;
        else p = pos;
    }*/
    printf("%lld\n",ans);

    return 0;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
cake3.cpp:88:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N; i++) scanf("%d %d",&cake[i].second,&cake[i].first);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...