Submission #1195776

#TimeUsernameProblemLanguageResultExecution timeMemory
1195776badge881Bikeparking (EGOI24_bikeparking)C++20
100 / 100
99 ms15444 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5 + 10;
int n;
vector<int> x, y;

int main()
{
    scanf("%d", &n);
    x.resize(n), y.resize(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &x[i]);

    for (int i = 0; i < n; i++)
        scanf("%d", &y[i]);

    int sm = 0;
    for (int i = 0; i < n; i++)
        sm += y[i];

    for (int i = 0; i < n; i++)
    {
        x[i] = min(sm, x[i]);
        sm -= x[i];
    }

    int ans = 0;
    set<int> st;
    for (int i = n - 1; i >= 0; i--)
    {
        while (x[i] > 0 && st.size())
        {
            int j = *st.begin();
            int mi = min(y[j], x[i]);
            x[i] -= mi;
            y[j] -= mi;
            ans += mi;
            if (y[j] == 0)
                st.erase(j);
        }

        if (y[i] > 0)
            st.insert(i);
    }

    for (int i = n - 1; i >= 0; i--)
        while (x[i] > 0)
        {
            int j = *st.begin();
            int mi = min(x[i], y[j]);
            x[i] -= mi;
            y[j] -= mi;
            if (i > j)
                ans -= mi;
            if (y[j] == 0)
                st.erase(j);
        }

    printf("%d\n", ans);

    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d", &x[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d", &y[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...