제출 #119751

#제출 시각아이디문제언어결과실행 시간메모리
119751PeppaPigSafety (NOI18_safety)C++14
100 / 100
405 ms19064 KiB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 2e5+5;

int n;
long k, now, high;
multiset<long> L, R;

int main() {
    scanf("%d %lld", &n, &k);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &now);
        high += now;
        L.emplace(now + i * k), R.emplace(now - i * k);
        while(*L.rbegin() - i * k > *R.begin() + i * k) {
            long l = *L.rbegin(), r = *R.begin();
            L.erase(L.find(l)), R.erase(R.find(r));
            L.emplace(r + 2 * i * k), R.emplace(l - 2 * i * k);
        }
        long pv = 0;
        while(!L.empty() && *L.begin() - (i + 1) * k <= 0) {
            high -= L.size() * abs(*L.begin() - i * k - pv);
            pv = *L.begin() - i * k;
            L.erase(L.begin());
        }
        high -= L.size() * abs(pv - k);
    }
    long pv = 0, m = L.size(), ans = high;
    for(long x : L) {
        ans -= abs(x - n * k - pv) * m--;
        pv = x - n * k;
    }
    printf("%lld\n", ans);

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

safety.cpp: In function 'int main()':
safety.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
safety.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &now);
         ~~~~~^~~~~~~~~~~~~~
#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...