Submission #1198504

#TimeUsernameProblemLanguageResultExecution timeMemory
1198504Ghulam_JunaidHoliday (IOI14_holiday)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "holiday.h"
using namespace std;

typedef long long ll;

ll findMaxAttraction(int n, int start, int d, vector<int> a){
    ll ans = 0;

    multiset<int> st;
    ll sm = 0;
    for (int i = start; i < n; i ++){
        int att = d - i + start;
        if (att <= 0) break;

        st.insert(a[i]);
        sm += a[i];

        while (st.size() > att){
            sm -= *st.begin();
            st.erase(st.begin());
        }

        ans = max(ans, sm);
    }

    st.clear();
    sm = 0;
    for (int i = start; i >= 0; i --){
        int att = d + i - start;
        if (att <= 0) break;

        st.insert(a[i]);
        sm += a[i];

        while (st.size() > att){
            sm -= *st.begin();
            st.erase(st.begin());
        }

        ans = max(ans, sm);
    }

    if (start != 0 and start != (n - 1)){
        for (int l = 0; l < start; l ++){
            st.clear();
            sm = 0;

            for (int r = l; r <= start; r ++)
                st.insert(a[i]), sm += a[i];
            for (int r = start + 1; r < n; r ++){
                int att = d - 2 * (start - l) - (r - start);
                if (att <= 0) break;

                while (st.size() > 0){
                    sm -= *st.begin();
                    st.erase(st.begin());
                }
                ans = max(ans, sm);
            }
        }

        for (int r = start + 1; r < n; r ++){
            st.clear();
            sm = 0;

            for (int l = start; l <= r; l ++)
                st.insert(a[l]), sm += a[i];
            for (int l = start - 1; l >= 0; l --){
                int att = d - 2 * (r - start) - (start - l);
                if (att <= 0) break;

                while (st.size() > 0){
                    sm -= *st.begin();
                    st.erase(st.begin());
                }
                ans = max(ans, sm);
            }
        }
    }

    return ans;
}

Compilation message (stderr)

holiday.cpp: In function 'll findMaxAttraction(int, int, int, std::vector<int>)':
holiday.cpp:50:29: error: 'i' was not declared in this scope
   50 |                 st.insert(a[i]), sm += a[i];
      |                             ^
holiday.cpp:68:42: error: 'i' was not declared in this scope
   68 |                 st.insert(a[l]), sm += a[i];
      |                                          ^