Submission #285794

# Submission time Handle Problem Language Result Execution time Memory
285794 2020-08-29T15:25:55 Z tbzard Safety (NOI18_safety) C++14
0 / 100
56 ms 5420 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int a[200005];
int main(){
    int n, h;
    scanf("%d%d", &n, &h);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    
    priority_queue<ll> L;
    priority_queue<ll, vector<ll>, greater<ll> > R;

    ll ans = 0;
    ll shift_L = 0, shift_R = 0;
    L.push(a[1]);
    R.push(a[1]);
    for(int i=1;i<=n;i++){
        shift_L -= h;
        shift_R += h;

        ll mn = L.top() + shift_L;
        ll mx = R.top() + shift_R;

        if(mn <= a[i] && a[i] <= mx){
            L.push(a[i]-shift_L);
            R.push(a[i]-shift_R);
        }
        else if(a[i] < mn){
            ans += mn-a[i];
            L.pop();
            L.push(a[i]-shift_L);
            L.push(a[i]-shift_L);
            R.push(mn-shift_R);
        }
        else{
            ans += a[i]-mx;
            R.pop();
            R.push(a[i]-shift_R);
            R.push(a[i]-shift_R);
            L.push(mx-shift_L);
        }
    }
    printf("%lld\n", ans);
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf("%d%d", &n, &h);
      |     ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:21:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     for(int i=1;i<=n;i++) scanf("%d", &a[i]);
      |                           ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 5420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -