제출 #238596

#제출 시각아이디문제언어결과실행 시간메모리
238596DodgeBallManPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
218 ms12008 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 10;
int n;
long long c[N], ans;
priority_queue<long long> q;

int main()
{
    scanf("%d",&n);
    for( int i = 1 ; i <= n ; i++ ) {
        long long a, b;
        scanf("%lld %lld",&a,&b);
        c[i] = c[i-1] + a - b;
    }
    for( int i = 1 ; i <= n ; i++ ) {
        if( c[i] > c[n] ) ans += c[i] - c[n], c[i] = c[n];
        if( c[i] < 0 ) ans -= c[i], c[i] = 0;
        q.emplace( c[i] );
        if( q.top() != c[i] ) {
            ans += q.top() - c[i];
            q.pop();
            q.emplace( c[i] );
        }
    }
    printf("%lld",ans);
    return 0;
}

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

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