Submission #679336

#TimeUsernameProblemLanguageResultExecution timeMemory
679336Cross_RatioHoliday (IOI14_holiday)C++14
24 / 100
5090 ms2924 KiB
#include <bits/stdc++.h>
#include "holiday.h"
using namespace std;
typedef long long ll;
int N, st, d;
int A[100005];
typedef pair<int, int> P;
ll findMaxAttraction(int _N, int _st, int _d, int attraction[]) {
    N = _N, st = _st, d = _d;
    int i, j;
    for(i=0;i<N;i++) A[i] = attraction[i];
    ll ans = 0;
    ll sum = 0;
    for(i=st;i>=0;i--) {
        int val = d;
        val -= 2*(st - i);
        if(val <= 0) break;
        priority_queue<int, vector<int>, greater<int>> PQ;
        ll cnt = 0;
        for(int j = i; j <= st; j++) {
            cnt += A[j];
            PQ.push(A[j]);
            while(PQ.size()>val) {
                cnt -= PQ.top();
                PQ.pop();
            }
        }
        ans = max(ans, cnt);
        for(j=st+1;j<N;j++) {
            cnt += A[j];
            PQ.push(A[j]);
            val--;
            if(val <= 0) break;
            while(PQ.size()>val) {
                cnt -= PQ.top();
                PQ.pop();
            }
            ans = max(ans, cnt);
        }
    }
    st = N-1-st;
    reverse(A, A+N);
    for(i=st;i>=0;i--) {
        int val = d;
        val -= 2*(st - i);
        if(val <= 0) break;
        priority_queue<int, vector<int>, greater<int>> PQ;
        ll cnt = 0;
        for(int j = i; j <= st; j++) {
            cnt += A[j];
            PQ.push(A[j]);
            while(PQ.size()>val) {
                cnt -= PQ.top();
                PQ.pop();
            }
        }
        ans = max(ans, cnt);
        for(j=st+1;j<N;j++) {
            cnt += A[j];
            PQ.push(A[j]);
            val--;
            if(val <= 0) break;
            while(PQ.size()>val) {
                cnt -= PQ.top();
                PQ.pop();
            }
            ans = max(ans, cnt);
        }
    }
    return ans;
}

Compilation message (stderr)

holiday.cpp: In function 'll findMaxAttraction(int, int, int, int*)':
holiday.cpp:23:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |             while(PQ.size()>val) {
      |                   ~~~~~~~~~^~~~
holiday.cpp:34:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |             while(PQ.size()>val) {
      |                   ~~~~~~~~~^~~~
holiday.cpp:52:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |             while(PQ.size()>val) {
      |                   ~~~~~~~~~^~~~
holiday.cpp:63:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |             while(PQ.size()>val) {
      |                   ~~~~~~~~~^~~~
holiday.cpp:13:8: warning: unused variable 'sum' [-Wunused-variable]
   13 |     ll sum = 0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...