Submission #1243585

#TimeUsernameProblemLanguageResultExecution timeMemory
1243585nvc2k8Garage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h>
#define TASK "akjdkasd"
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define all(C) C.begin(), C.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INT_LIM = 2147483647;
const ll LL_LIM = 9223372036854775807;
template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;}
template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;}
///------------------------------------------///
int n,m;
ll a[105], b[10005];
int f[105];
ll ans = 0;

void inp()
{
    cin >> n >> m;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, m) cin >> b[i];
}

void solve()
{
    queue<int> q;
    FOR(t, 1, 2*m)
    {
        int x;
        cin >> x;
        if (x>0)
        {
            bool flag = true;
            FOR(i, 1, n) if (f[i]==0)
            {
                f[i] = x;
                ans+= a[i]*b[x];
                flag = false;
                break;
            }
            if (flag) q.push(x);
        }
        else
        {
            x = -x;
            FOR(i, 1, n) if (f[i]==x)
            {
                f[i] = 0;
                if (!q.empty())
                {
                    ans+= a[i]*b[q.front()];
                    f[i] = q.front();
                    q.pop();
                }
                break;
            }
        }
    }
    cout << ans;
}

signed main()
{
    ///--------------------------///
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    if (fopen(TASK".INP","r")!=NULL)
    {
        freopen(TASK".INP","r",stdin);
        freopen(TASK".OUT","w",stdout);
    }
    ///--------------------------///

    int NTEST = 1;
    bool codeforces = 0;
    if (codeforces) cin >> NTEST;

    while (NTEST--)
    {
        inp();
        solve();
    }

    return 0;
}

///------------------------------------------///

Compilation message (stderr)

garage.cpp: In function 'int main()':
garage.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(TASK".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
garage.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(TASK".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...