제출 #1356411

#제출 시각아이디문제언어결과실행 시간메모리
13564114o2aPotatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
174 ms27832 KiB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define _F "what"
using namespace std;
typedef long long ll;

void solve()
{
    int n; cin>>n;
    vector<ll> x(n+1);
    ll A = 0, B = 0, res = 0;
    for (int i = 1; i <= n; ++i)
    {
        int a, b; cin>>a>>b;
        A += a, B += b;
        x[i] = A - B;
    }
    for (int i = 1; i < n; ++i)
    {
        if (x[i] < 0)
        {
            res += -x[i];
            x[i] = 0;
        }
        if (x[i] > x[n])
        {
            res += x[i] - x[n];
            x[i] = x[n];
        }
    }
    multiset<ll> S; S.insert(x[1]);
    for (int i = 2; i <= n; ++i)
    {
        S.insert(x[i]);
        if (*prev(S.end()) > x[i])
        {
            res += *prev(S.end()) - x[i];
            S.insert(x[i]);
            S.erase(prev(S.end()));
        }
    }
    cout<<res;
}

int main()
{
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    else if (fopen("test.inp", "r"))
    {
        freopen("test.inp", "r", stdin);
        //freopen("test.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int Test = 1; //cin>>Test;
    while (Test--) solve();
}

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

bulves.cpp: In function 'int main()':
bulves.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(_F".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(_F".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…