Submission #558558

# Submission time Handle Problem Language Result Execution time Memory
558558 2022-05-07T14:18:10 Z stefantaga Feast (NOI19_feast) C++14
100 / 100
341 ms 12772 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int n,i,k;
ll v[300005],din[300005],cnt[300005],sum[300005];
ll suma(int st,int dr)
{
    return sum[dr]-sum[st-1];
}
ll ok (ll mij)
{
    deque <int> st;
    st.push_back(0);
    for (int i=1; i<=n; i++)
    {
        din[i]=din[i-1];
        cnt[i]=cnt[i-1];
        if (din[i]<din[i-1]+mij)
        {
            din[i]=din[i-1]+mij;
            cnt[i]=cnt[i-1]+1;
        }
        if (st.empty())
        {
            if (din[i]<v[i]+din[i-1]+mij)
            {
                din[i]=v[i]+din[i-1]+mij;
                cnt[i]=1+cnt[i-1];
            }
        }
        else
        {
            if (din[i]<din[st.front()]+suma(st.front()+1,i)+mij)
            {
                din[i]=din[st.front()]+suma(st.front()+1,i)+mij;
                cnt[i]=1+cnt[st.front()];
            }
        }
        while (!st.empty()&&din[st.back()]+suma(st.back()+1,i+1)<=v[i+1]+din[i])
        {
            st.pop_back();
        }
        st.push_back(i);
    }
    return cnt[n];
}
ll st,dr,sol;
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
#ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
#endif // HOME
    cin>>n>>k;
    for (i=1; i<=n; i++)
    {
        cin>>v[i];
        sum[i]=sum[i-1]+v[i];
    }
    st=-1e16;
    dr=1e16;
    while (st<=dr)
    {
        ll mij = (st+dr)/2;
        auto salut = ok(mij);
        if (salut>=k)
        {
            sol=mij;
            dr=mij-1;
        }
        else
        {
            st=mij+1;
        }
    }
    deque <int> st;
    st.push_back(0);
    for (int i=1; i<=n; i++)
    {
        din[i]=din[i-1];
        cnt[i]=cnt[i-1];
        if (din[i]<din[i-1]+sol)
        {
            din[i]=din[i-1]+sol;
            cnt[i]=cnt[i-1]+1;
        }
        if (st.empty())
        {
            if (din[i]<v[i]+din[i-1]+sol)
            {
                din[i]=v[i]+din[i-1]+sol;
                cnt[i]=1+cnt[i-1];
            }
        }
        else
        {
            int poz=st.front();
            if (din[i]<din[poz]+suma(poz+1,i)+sol)
            {
                din[i]=din[poz]+suma(poz+1,i)+sol;
                cnt[i]=1+cnt[poz];
            }
        }
        while (!st.empty()&&din[st.back()]+suma(st.back()+1,i+1)<=v[i+1]+din[i])
        {
            st.pop_back();
        }
        st.push_back(i);
    }
    cout<<din[n]-cnt[n]*sol;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 162 ms 10572 KB Output is correct
2 Correct 169 ms 10760 KB Output is correct
3 Correct 173 ms 10828 KB Output is correct
4 Correct 173 ms 10804 KB Output is correct
5 Correct 176 ms 10700 KB Output is correct
6 Correct 168 ms 10572 KB Output is correct
7 Correct 172 ms 10576 KB Output is correct
8 Correct 170 ms 10724 KB Output is correct
9 Correct 170 ms 10564 KB Output is correct
10 Correct 169 ms 10740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 10116 KB Output is correct
2 Correct 184 ms 10632 KB Output is correct
3 Correct 175 ms 10472 KB Output is correct
4 Correct 167 ms 10504 KB Output is correct
5 Correct 185 ms 10696 KB Output is correct
6 Correct 171 ms 10564 KB Output is correct
7 Correct 168 ms 10764 KB Output is correct
8 Correct 182 ms 10948 KB Output is correct
9 Correct 175 ms 10612 KB Output is correct
10 Correct 166 ms 10400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 9712 KB Output is correct
2 Correct 318 ms 12480 KB Output is correct
3 Correct 322 ms 12576 KB Output is correct
4 Correct 312 ms 12468 KB Output is correct
5 Correct 317 ms 12492 KB Output is correct
6 Correct 316 ms 12688 KB Output is correct
7 Correct 323 ms 12704 KB Output is correct
8 Correct 312 ms 12532 KB Output is correct
9 Correct 326 ms 12736 KB Output is correct
10 Correct 320 ms 12772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 336 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 10572 KB Output is correct
2 Correct 169 ms 10760 KB Output is correct
3 Correct 173 ms 10828 KB Output is correct
4 Correct 173 ms 10804 KB Output is correct
5 Correct 176 ms 10700 KB Output is correct
6 Correct 168 ms 10572 KB Output is correct
7 Correct 172 ms 10576 KB Output is correct
8 Correct 170 ms 10724 KB Output is correct
9 Correct 170 ms 10564 KB Output is correct
10 Correct 169 ms 10740 KB Output is correct
11 Correct 170 ms 10116 KB Output is correct
12 Correct 184 ms 10632 KB Output is correct
13 Correct 175 ms 10472 KB Output is correct
14 Correct 167 ms 10504 KB Output is correct
15 Correct 185 ms 10696 KB Output is correct
16 Correct 171 ms 10564 KB Output is correct
17 Correct 168 ms 10764 KB Output is correct
18 Correct 182 ms 10948 KB Output is correct
19 Correct 175 ms 10612 KB Output is correct
20 Correct 166 ms 10400 KB Output is correct
21 Correct 315 ms 9712 KB Output is correct
22 Correct 318 ms 12480 KB Output is correct
23 Correct 322 ms 12576 KB Output is correct
24 Correct 312 ms 12468 KB Output is correct
25 Correct 317 ms 12492 KB Output is correct
26 Correct 316 ms 12688 KB Output is correct
27 Correct 323 ms 12704 KB Output is correct
28 Correct 312 ms 12532 KB Output is correct
29 Correct 326 ms 12736 KB Output is correct
30 Correct 320 ms 12772 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 328 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 340 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 3 ms 336 KB Output is correct
56 Correct 3 ms 340 KB Output is correct
57 Correct 3 ms 364 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 340 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
61 Correct 291 ms 12464 KB Output is correct
62 Correct 293 ms 12752 KB Output is correct
63 Correct 316 ms 12380 KB Output is correct
64 Correct 309 ms 12648 KB Output is correct
65 Correct 315 ms 12648 KB Output is correct
66 Correct 307 ms 12620 KB Output is correct
67 Correct 315 ms 12428 KB Output is correct
68 Correct 341 ms 12668 KB Output is correct
69 Correct 313 ms 12360 KB Output is correct
70 Correct 316 ms 12364 KB Output is correct