제출 #968484

#제출 시각아이디문제언어결과실행 시간메모리
968484tsetArt Exhibition (JOI18_art)C++14
0 / 100
0 ms348 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int INF = 1e18 +42;

signed main()
{
    int N;
    scanf("%lld", &N);
    vector<pair<int, int>> tab;
    for(int iTab = 0; iTab < N; iTab++)
    {
        int A, B;
        scanf("%lld%lld", &A, &B);
        tab.push_back({A, B});
    }
    sort(tab.begin(), tab.end());

    vector<int> cumulS(N, 0);
    cumulS[0] = tab[0].second;
    for(int i= 1; i<N; i++)
    {
        cumulS[i] = cumulS[i-1] + tab[i].second;
    }
    
    vector<int> SMalus(N);
    int valueMax = -INF;
    int idxMax = -INF;
    for(int i=0; i<N; i++)
    {
        SMalus[i] = cumulS[i] - tab[i].first;
        if(SMalus[i] >= valueMax)
        {
            valueMax = SMalus[i];
            idxMax = i;
        }
    }
    int ans = valueMax +tab[0].first;
    for(int i=1; i<= idxMax; i++)
    {
        ans = max(ans, valueMax - cumulS[i-1] + tab[i].first);
    }
    printf("%lld\n", ans);

}

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

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