204192026-01-06 18:04:35ZsoltBenzinkút üzemeltetés (55)cpp17Wrong answer 6/552ms560 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>tav(n+1);
    vector<int>penz(n+1);
    for(int i=1; i<=n; i++)
    {
        cin>>tav[i]>>penz[i];
    }
    vector<int>profit(n+1,0);
    vector<int>epit(n+1,false);
    profit[1]=penz[1];
    epit[1]=penz[1]>0;
    for(int i=2; i<=n; i++)
    {
       if(penz[i]+profit[i-2]>profit[i-1])
       {
           profit[i]=profit[i-2]+penz[i];
           epit[i]=true;
       }
       else
       {
           profit[i]=profit[i-1];
           epit[i]=false;
       }
    }
    vector<int>a;
    int i=n,j;
    while(i>=1)
    {
        if(epit[i])
        {
            a.push_back(i);
            i-=2;
        }
        else
        {
            i--;
        }
    }
    cout<<profit[n]<<endl;
    cout<<a.size()<<" ";
    for(i=a.size()-1; i>=0; i--)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/55
1Accepted0/01ms504 KiB
2Wrong answer0/02ms316 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms508 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Wrong answer0/31ms500 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/31ms316 KiB
11Wrong answer0/31ms508 KiB
12Wrong answer0/31ms560 KiB
13Wrong answer0/41ms316 KiB
14Wrong answer0/41ms316 KiB
15Wrong answer0/51ms408 KiB
16Wrong answer0/61ms316 KiB
17Wrong answer0/62ms508 KiB