CSES - Aalto Competitive Programming 2024 - wk3 - Mon - Results
Submission details
Task:Wheel of fortune
Sender:aalto2024b_005
Submission time:2024-09-16 17:47:59 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:73:23: error: no matching function for call to 'max(LL&, int)'
   73 |     printf("%lld", max(ans, 0));
      |                    ~~~^~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from input/code.cpp:3:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
input/code.cpp:73:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   73 |     printf("%lld", max(ans, 0));
      |                    ~~~^~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from input/code.cpp:3:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> _Tp std::max(std::initi...

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
typedef long long LL;
using std::max;
const int N=1e5+3;

const LL INF = 0x3fffffffffffffff;

LL a[N], f[N][10];

void Test()
{
    freopen("temp\\in.txt", "r", stdin);
}
int main()
{
    // Test();
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%lld", &a[i]);

    f[1][1] = a[1];
    f[1][5] = -a[1];

    f[2][1] = -INF;
    f[2][2] = f[1][1] - a[2];
    f[2][3] = f[1][1];
    f[2][3+1] = f[1][5] + a[2];
    f[2][3+2] = -INF;
    f[2][3+3] = f[1][5];
    f[2][6+1] = f[1][9] + a[2];
    f[2][6+2] = f[1][9] - a[2];
    f[2][6+3] = -INF;

    for(int i=3; i<n; i++)
    {
        for(int j=0; j<=6; j+=3)
        {
            // choose
            f[i][j+1] = max(f[i-1][j+2], f[i-1][j+3]);
            f[i][j+1] += a[i];
            // unchoose
            f[i][j+2] = max(f[i-1][j+1], f[i-1][j+3]);
            f[i][j+2] -= a[i];
            // ignore
            f[i][j+3] = max(f[i-1][j+1], f[i-1][j+2]);
        }
    }

    f[n][1] = -INF;
    f[n][2] = f[n-1][3] - a[n];
    f[n][3] = f[n-1][2];
    f[n][3+1] = f[n-1][3+3] + a[n];
    f[n][3+2] = -INF;
    f[n][3+3] = f[n-1][3+1];
    f[n][6+1] = f[n-1][6+2] + a[n];
    f[n][6+2] = f[n-1][6+1] - a[n];
    f[n][6+3] = -INF;

    LL ans = -INF;
    for(int i=1; i<=9; i++)
        ans = max(ans, f[n][i]);

// for(int i=1; i<=n; i++)
// {
//     for(int j=1; j<=9; j++)
//         printf("%d ", f[i][j]);
//     putchar('\n');
// }

    printf("%lld", max(ans, 0));
    return 0;
}