Submission #578928

# Submission time Handle Problem Language Result Execution time Memory
578928 2022-06-18T08:09:49 Z mousebeaver Two Dishes (JOI19_dishes) C++14
0 / 100
175 ms 28516 KB
#define ll long long
#define ull unsigned ll
#define pli pair<ll, int>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> s(n);
    vector<ll> p(n);
    for(int i = 0; i < n; i++)
    {
        cin>>a[i]>>s[i]>>p[i];
    }
    vector<ll> b(m);
    vector<ll> t(m);
    vector<ll> q(m);
    for(int i = 0; i < m; i++)
    {
        cin>>b[i]>>t[i]>>q[i];
    }

    vector<ll> prea(n);
    prea[0] = a[0];
    for(int i = 1; i < n; i++)
    {
        prea[i] = prea[i-1]+a[i];
    }
    vector<ll> preb(m);
    preb[0] = b[0];
    for(int i = 1; i < m; i++)
    {
        preb[i] = preb[i-1]+b[i];
    }
    vector<ll> prep(n);
    prep[0] = p[0];
    for(int i = 1; i < n; i++)
    {
        prep[i] = prep[i-1]+p[i];
    }
    vector<ll> preq(n);
    preq[0] = q[0];
    for(int i = 1; i < m; i++)
    {
        preq[i] = preq[i-1]+q[i];
    }
    //cout<<"HERE"<<endl;

    ll time = s[0];
    int qindex = m-1;
    while(qindex >= 0 && preb[qindex] > time)
    {
        qindex--;
    }
    ll output = 0;
    if(qindex >= 0)
    {
        output = max(output, preq[qindex]);
    }
    //cout<<"HERE"<<endl;

    for(int i = 0; i < n && prea[i] <= time; i++)
    {
        //cout<<"TEST"<<endl;
        while(qindex >= 0 && preb[qindex]+prea[i] > time)
        {
            qindex--;
        }
        if(qindex >= 0)
        {
            output = max(output, prep[i]+preq[qindex]);
        }
        else
        {
            output = max(output, prep[i]);
        }
    }
    cout<<output<<"\n";

    /*vector<vector<ll>> dp(n+1, vector<ll> (m+1, 0));
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= m; j++)
        {
            ll time = 0;
            if(i > 0)
            {
                time += prea[i-1];
            }
            if(j > 0)
            {
                time += preb[j-1];
            }

            //Dish 1:
            if(i > 0)
            {
                ll score = dp[i-1][j];
                if(time <= s[i-1])
                {
                    score += p[i-1];
                }
                dp[i][j] = max(dp[i][j], score);
            }
            if(j > 0)
            {
                ll score = dp[i][j-1];
                if(time <= t[j-1])
                {
                    score += q[j-1];
                }
                dp[i][j] = max(dp[i][j], score);
            }
        }
    }

    cout<<dp[n][m]<<"\n";*/

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 163 ms 15904 KB Output is correct
2 Runtime error 175 ms 28516 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 163 ms 15904 KB Output is correct
2 Runtime error 175 ms 28516 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 163 ms 15904 KB Output is correct
2 Runtime error 175 ms 28516 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -