제출 #250471

#제출 시각아이디문제언어결과실행 시간메모리
250471jwvg0425Holiday (IOI14_holiday)C++17
30 / 100
5080 ms2260 KiB
#include"holiday.h"
#include <queue>
#include <algorithm>
#define all(x) (x).begin(), (x).end()

using namespace std;

long long int fromZero(int n, int d, int attraction[])
{
    priority_queue<int, vector<int>, greater<int>> q;

    long long int now = 0;
    long long int ans = 0;

    for (int i = 0; i < n; i++)
    {
        // 0 -> i까지 간다고 했을 때 관광지 방문에 쓸 수 있는 날짜
        int canVisit = d - i;

        now += attraction[i];
        q.push(attraction[i]);

        while (q.size() > canVisit)
        {
            now -= q.top();
            q.pop();
        }

        ans = max(ans, now);
    }

    return ans;
}

long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
    if (start == 0)
        return fromZero(n, d, attraction);

    long long int ans = 0;

    for (int l = start; l >= 0; l--)
    {
        for (int r = start; r < n; r++)
        {
            // l ~ r 구간
            int use = r - l + min(r - start, start - l);
            int remain = d - use;

            vector<int> at;
            for (int i = l; i <= r; i++)
                at.push_back(attraction[i]);

            sort(all(at), greater<int>());

            long long int now = 0;

            for (int i = 0; i < min<int>(remain, at.size()); i++)
                now += at[i];

            ans = max(ans, now);
        }
    }

    return ans;
}

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

holiday.cpp: In function 'long long int fromZero(int, int, int*)':
holiday.cpp:23:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (q.size() > canVisit)
                ~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...