Submission #559493

#TimeUsernameProblemLanguageResultExecution timeMemory
559493AmylopectinSafety (NOI18_safety)C++14
100 / 100
63 ms5452 KiB
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const int mxn = 8e5 + 10;
struct cmple
{
    bool operator () (const long long &l,const long long &r)
    {
        return l < r;
    }
};
struct cmpri
{
    bool operator () (const long long &l,const long long &r)
    {
        return l > r;
    }
};
priority_queue<long long, vector<long long>, cmple> lef;
priority_queue<long long, vector<long long>, cmpri> rig;
int main()
{
    long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
    scanf("%lld %lld",&n,&h);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&ch);
        if(i == 0)
        {
            lef.push(ch);
            rig.push(ch);
        }
        else
        {
            sh = h * i;
            lpo = lef.top() - sh;
            rpo = rig.top() + sh;
            if(ch < lpo)
            {
                rig.push(lpo - sh);
                lef.push(ch + sh);
                lef.push(ch + sh);
                lef.pop();
                ans += lpo - ch;
            }
            else if(ch > rpo)
            {
                lef.push(rpo + sh);
                rig.push(ch - sh);
                rig.push(ch - sh);
                rig.pop();
                ans += ch - rpo;
            }
            else
            {
                lef.push(ch + sh);
                rig.push(ch - sh);
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:25:17: warning: unused variable 'j' [-Wunused-variable]
   25 |     long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
      |                 ^
safety.cpp:25:21: warning: unused variable 'm' [-Wunused-variable]
   25 |     long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
      |                     ^
safety.cpp:25:25: warning: unused variable 'k' [-Wunused-variable]
   25 |     long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
      |                         ^
safety.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%lld %lld",&n,&h);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
safety.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld",&ch);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...