Submission #531487

# Submission time Handle Problem Language Result Execution time Memory
531487 2022-02-28T21:17:25 Z Rafi22 Akcija (COCI21_akcija) C++14
10 / 110
38 ms 632 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

vector<ll>V[2007];
priority_queue<pair<pair<int,ll>,pair<int,int>>>Q;
vector<pair<pair<int,ll>,pair<int,int>>>best;
vector<ll>ord;

void add(int i,int j)
{
    ll w=best[j].st.nd;
    int x=best[j].nd.st,y=best[j].nd.nd,s=best[j].st.st;
    if(x<sz(ord))
    {
        if(y<sz(V[i]))
        {
            if(ord[x]>V[i][y])
            {
                Q.push({{s+1,w+ord[x]},{x+y+1,j}});
                best[j].nd.st++;
            }
            else
            {
                Q.push({{s+1,w+V[i][y]},{x+y+1,j}});
                best[j].nd.nd++;
            }
        }
        else
        {
            Q.push({{s+1,w+ord[x]},{x+y+1,j}});
            best[j].nd.st++;
        }
    }
    else if(y<sz(V[i]))
    {
        Q.push({{s+1,w+V[i][y]},{x+y+1,j}});
        best[j].nd.nd++;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k,d;
    ll w;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>w>>d;
        V[d].pb(-w);
    }
    best.pb({{0,0},{0,0}});
    for(int i=n;i>0;i--)
    {
        sort(all(V[i]),greater<ll>());
        while(sz(Q)>0) Q.pop();
        vector<pair<pair<int,ll>,pair<int,int>>>nbest;
        for(int j=0;j<sz(best);j++)
        {
            Q.push({{best[j].st.st,best[j].st.nd},{best[j].nd.st,-1}});
            add(i,j);
        }
        while(sz(Q)>0&&sz(nbest)<k)
        {
            ll w=Q.top().st.nd;
            int x=Q.top().nd.st,j=Q.top().nd.nd,s=Q.top().st.st;
            Q.pop();
            nbest.pb({{s,w},{x,0}});
            if(j!=-1) add(i,j);
        }
        best=nbest;
        for(auto x:V[i]) ord.pb(x);
        sort(all(ord),greater<ll>());
    }
    for(auto x:best) cout<<x.st.st<<" "<<-x.st.nd<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 460 KB Output is correct
2 Correct 17 ms 460 KB Output is correct
3 Correct 14 ms 460 KB Output is correct
4 Correct 14 ms 456 KB Output is correct
5 Correct 19 ms 588 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 368 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 372 KB Output is correct
10 Correct 7 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 460 KB Output is correct
2 Correct 17 ms 460 KB Output is correct
3 Correct 14 ms 460 KB Output is correct
4 Correct 14 ms 456 KB Output is correct
5 Correct 19 ms 588 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 368 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 372 KB Output is correct
10 Correct 7 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 38 ms 376 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 460 KB Output is correct
2 Correct 17 ms 460 KB Output is correct
3 Correct 14 ms 460 KB Output is correct
4 Correct 14 ms 456 KB Output is correct
5 Correct 19 ms 588 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 368 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 372 KB Output is correct
10 Correct 7 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 38 ms 376 KB Output isn't correct
15 Halted 0 ms 0 KB -