CSES - Aalto Competitive Programming 2024 - wk3 - Mon - Results
Submission details
Task:Wheel of fortune
Sender:AleksandrPolitov
Submission time:2024-09-16 17:31:15 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.01 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43ACCEPTED0.00 sdetails
#44ACCEPTED0.00 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#48ACCEPTED0.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.00 sdetails
#51ACCEPTED0.00 sdetails
#52ACCEPTED0.00 sdetails
#53ACCEPTED0.00 sdetails
#54ACCEPTED0.00 sdetails
#55ACCEPTED0.00 sdetails
#56ACCEPTED0.00 sdetails
#57ACCEPTED0.00 sdetails
#58ACCEPTED0.00 sdetails
#59ACCEPTED0.00 sdetails
#60ACCEPTED0.00 sdetails
#61ACCEPTED0.00 sdetails
#62ACCEPTED0.00 sdetails
#63ACCEPTED0.00 sdetails
#64ACCEPTED0.00 sdetails
#65ACCEPTED0.00 sdetails
#66ACCEPTED0.00 sdetails
#67ACCEPTED0.00 sdetails
#68ACCEPTED0.00 sdetails
#69ACCEPTED0.00 sdetails
#70ACCEPTED0.00 sdetails
#71ACCEPTED0.00 sdetails
#72ACCEPTED0.00 sdetails
#73ACCEPTED0.00 sdetails
#74ACCEPTED0.00 sdetails
#75ACCEPTED0.00 sdetails
#76ACCEPTED0.00 sdetails
#77ACCEPTED0.00 sdetails
#78ACCEPTED0.00 sdetails
#79ACCEPTED0.00 sdetails
#80ACCEPTED0.00 sdetails
#81ACCEPTED0.00 sdetails
#82ACCEPTED0.00 sdetails
#83ACCEPTED0.00 sdetails
#84ACCEPTED0.00 sdetails
#85ACCEPTED0.00 sdetails
#86ACCEPTED0.01 sdetails
#87ACCEPTED0.02 sdetails
#88ACCEPTED0.02 sdetails
#89ACCEPTED0.02 sdetails
#90ACCEPTED0.00 sdetails
#91ACCEPTED0.00 sdetails
#92ACCEPTED0.00 sdetails
#93ACCEPTED0.00 sdetails
#94ACCEPTED0.00 sdetails
#95ACCEPTED0.00 sdetails
#96ACCEPTED0.01 sdetails
#97ACCEPTED0.00 sdetails
#98ACCEPTED0.01 sdetails
#99ACCEPTED0.02 sdetails
#100ACCEPTED0.00 sdetails

Code

#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define char unsigned char
#define rep(i, a, b) for(int i=a; i< (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back

#define LSOne(S) ((S) & -(S))

using namespace std;
// mt19937 rnd(239);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()

template<class T>
istream& operator>> (istream& is, complex<T>& p) {
    T value;
    is >> value;
    p.real(value);
    is >> value;
    p.imag(value);
    return is;
}

typedef long long ll;
typedef long double ld;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif

template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;}
template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;}

const int INF = 1e9; // 10^9 = 1B is < 2^31-1
const ll LLINF = 4e18; // 4*10^18 is < 2^63-1
const double EPS = 1e-9;
const ll MOD = 1e9+7;

const int N=2e5+10;
ll dp[N][3][3];

int solve() {
    int n; std::cin >> n;
    vector<ll> v(n+1);
    for (int i = 1; i <= n; i++) std::cin >> v[i];


    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                dp[i][j][k]=-INF;
            }
        }
    }



    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            dp[0][i][j]=0;
        }
    }


    dp[1][0][0]=v[1];
    dp[1][1][1]=-v[1];
    dp[1][2][2]=0;
    

    


    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            //dp[i][0]=max({dp[i][0], dp[i-1][1]+v[i], dp[i-1][2]+v[i]});
            //dp[i][1]=max({dp[i][1], dp[i-1][0]-v[i], dp[i-1][2]-v[i]});
            //dp[i][2]=max({dp[i][2], dp[i-1][0], dp[i-1][1]});


            
            dp[i][0][j]=max({dp[i][0][j], dp[i-1][1][j]+v[i], dp[i-1][2][j]+v[i]});
            dp[i][1][j]=max({dp[i][1][j], dp[i-1][0][j]-v[i], dp[i-1][2][j]-v[i]});
            dp[i][2][j]=max({dp[i][2][j], dp[i-1][0][j], dp[i-1][1][j]});
        }

        /*
        if(dp[i-1][1]+v[i]>dp[i][0]) {
            dp[i][0]=dp[i-1][1]+v[i];
            dp2[i][0]=1;
        }
        if(dp[i-1][2]+v[i]>dp[i][0]) {
            dp[i][0]=dp[i-1][2]+v[i];
            dp2[i][0]=2;
        }
        */



        /*
        if(dp[i-1][0]-v[i]>dp[i][1]) {
            dp[i][1]=dp[i-1][0]-v[i];
            dp2[i][1]=0;
        }

        if(dp[i-1][2]-v[i]>dp[i][1]) {
            dp[i][1]=dp[i-1][2]-v[i];
            dp2[i][1]=2;
        }


        if(dp[i-1][0]>dp[i][2]) {
            dp[i][2]=dp[i-1][0];
            dp2[i][2]=0;
        }
        if(dp[i-1][2]>dp[i][2]) {
            dp[i][2]=dp[i-1][0];
            dp2[i][2]=0;
        }

        */




    }


    //__print(dp[1]); std::cout  << std::endl;
    //__print(dp[n]); std::cout  << std::endl;
    
    ll res=max({dp[n][0][1], dp[n][0][2], dp[n][1][0], dp[n][1][2], dp[n][2][0], dp[n][2][1]});

    std::cout << res << std::endl;
    
    
    return 0;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1;
    //cin >> TET;
    for (int i = 1; i <= TET; i++) {
        #ifdef ONPC
            cout << "TEST CASE#" << i << endl;
        #endif
        
        if (solve()) {
            break;
        }

        #ifdef ONPC
            cout << "__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
}

Test details

Test 1

Verdict: ACCEPTED

input
3
41702 99720 72033 

correct output
58018

user output
58018

Test 2

Verdict: ACCEPTED

input
4
41702 99720 72033 93257 

correct output
192977

user output
192977

Test 3

Verdict: ACCEPTED

input
5
41702 99720 72033 93257 11 

correct output
192966

user output
192966

Test 4

Verdict: ACCEPTED

input
6
41702 99720 72033 93257 11 128...

correct output
205789

user output
205789

Test 5

Verdict: ACCEPTED

input
7
41702 99720 72033 93257 11 128...

correct output
223199

user output
223199

Test 6

Verdict: ACCEPTED

input
10
41702 99720 72033 93257 11 128...

correct output
329303

user output
329303

Test 7

Verdict: ACCEPTED

input
3
43600 18508 2592 

correct output
41008

user output
41008

Test 8

Verdict: ACCEPTED

input
4
43600 18508 2592 93155 

correct output
111663

user output
111663

Test 9

Verdict: ACCEPTED

input
5
43600 18508 2592 93155 54967 

correct output
134163

user output
134163

Test 10

Verdict: ACCEPTED

input
6
43600 18508 2592 93155 54967 9...

correct output
206437

user output
206437

Test 11

Verdict: ACCEPTED

input
7
43600 18508 2592 93155 54967 9...

correct output
228937

user output
228937

Test 12

Verdict: ACCEPTED

input
10
43600 18508 2592 93155 54967 9...

correct output
286966

user output
286966

Test 13

Verdict: ACCEPTED

input
3
55080 7072 70815 

correct output
63743

user output
63743

Test 14

Verdict: ACCEPTED

input
4
55080 7072 70815 83996 

correct output
125895

user output
125895

Test 15

Verdict: ACCEPTED

input
5
55080 7072 70815 83996 29090 

correct output
132004

user output
132004

Test 16

Verdict: ACCEPTED

input
6
55080 7072 70815 83996 29090 1...

correct output
154985

user output
154985

Test 17

Verdict: ACCEPTED

input
7
55080 7072 70815 83996 29090 1...

correct output
144137

user output
144137

Test 18

Verdict: ACCEPTED

input
10
96704 90063 54724 17269 97269 ...

correct output
389952

user output
389952

Test 19

Verdict: ACCEPTED

input
3
96704 90063 54724 

correct output
41980

user output
41980

Test 20

Verdict: ACCEPTED

input
4
96704 90063 54724 17269 

correct output
151428

user output
151428

Test 21

Verdict: ACCEPTED

input
5
96704 90063 54724 17269 97269 

correct output
170063

user output
170063

Test 22

Verdict: ACCEPTED

input
6
96704 90063 54724 17269 97269 ...

correct output
248697

user output
248697

Test 23

Verdict: ACCEPTED

input
7
96704 90063 54724 17269 97269 ...

correct output
241545

user output
241545

Test 24

Verdict: ACCEPTED

input
10
96704 90063 54724 17269 97269 ...

correct output
389952

user output
389952

Test 25

Verdict: ACCEPTED

input
50
41702 99720 72033 93257 11 128...

correct output
1508857

user output
1508857

Test 26

Verdict: ACCEPTED

input
50
43600 18508 2592 93155 54967 9...

correct output
1261022

user output
1261022

Test 27

Verdict: ACCEPTED

input
50
55080 7072 70815 83996 29090 1...

correct output
1204485

user output
1204485

Test 28

Verdict: ACCEPTED

input
50
96704 90063 54724 17269 97269 ...

correct output
1548881

user output
1548881

Test 29

Verdict: ACCEPTED

input
250
41702 99720 72033 93257 11 128...

correct output
7048856

user output
7048856

Test 30

Verdict: ACCEPTED

input
250
43600 18508 2592 93155 54967 9...

correct output
7355456

user output
7355456

Test 31

Verdict: ACCEPTED

input
250
55080 7072 70815 83996 29090 1...

correct output
6879335

user output
6879335

Test 32

Verdict: ACCEPTED

input
250
96704 90063 54724 17269 97269 ...

correct output
7241700

user output
7241700

Test 33

Verdict: ACCEPTED

input
900
41702 99720 72033 93257 11 128...

correct output
25585084

user output
25585084

Test 34

Verdict: ACCEPTED

input
900
43600 18508 2592 93155 54967 9...

correct output
25559325

user output
25559325

Test 35

Verdict: ACCEPTED

input
900
55080 7072 70815 83996 29090 1...

correct output
25395388

user output
25395388

Test 36

Verdict: ACCEPTED

input
900
96704 90063 54724 17269 97269 ...

correct output
25722421

user output
25722421

Test 37

Verdict: ACCEPTED

input
10000
41702 99720 72033 93257 11 128...

correct output
286456959

user output
286456959

Test 38

Verdict: ACCEPTED

input
3
2 3 3 

correct output
1

user output
1

Test 39

Verdict: ACCEPTED

input
4
2 4 3 4 

correct output
8

user output
8

Test 40

Verdict: ACCEPTED

input
5
3 5 4 5 1 

correct output
9

user output
9

Test 41

Verdict: ACCEPTED

input
6
3 6 5 6 1 1 

correct output
13

user output
13

Test 42

Verdict: ACCEPTED

input
7
3 7 6 7 1 1 3 

correct output
16

user output
16

Test 43

Verdict: ACCEPTED

input
10
5 10 8 10 1 2 4 10 2 3 

correct output
35

user output
35

Test 44

Verdict: ACCEPTED

input
3
2 1 1 

correct output
1

user output
1

Test 45

Verdict: ACCEPTED

input
4
2 1 1 4 

correct output
5

user output
5

Test 46

Verdict: ACCEPTED

input
5
3 1 1 5 3 

correct output
7

user output
7

Test 47

Verdict: ACCEPTED

input
6
3 2 1 6 4 6 

correct output
14

user output
14

Test 48

Verdict: ACCEPTED

input
7
4 2 1 7 4 7 4 

correct output
17

user output
17

Test 49

Verdict: ACCEPTED

input
10
5 2 1 10 6 10 5 5 5 4 

correct output
31

user output
31

Test 50

Verdict: ACCEPTED

input
3
2 3 3 

correct output
1

user output
1

Test 51

Verdict: ACCEPTED

input
4
2 4 3 4 

correct output
8

user output
8

Test 52

Verdict: ACCEPTED

input
5
3 5 4 5 1 

correct output
9

user output
9

Test 53

Verdict: ACCEPTED

input
6
3 6 5 6 1 1 

correct output
13

user output
13

Test 54

Verdict: ACCEPTED

input
7
3 7 6 7 1 1 3 

correct output
16

user output
16

Test 55

Verdict: ACCEPTED

input
10
5 10 8 10 1 2 4 10 2 3 

correct output
35

user output
35

Test 56

Verdict: ACCEPTED

input
3
2 1 1 

correct output
1

user output
1

Test 57

Verdict: ACCEPTED

input
4
2 1 1 4 

correct output
5

user output
5

Test 58

Verdict: ACCEPTED

input
5
3 1 1 5 3 

correct output
7

user output
7

Test 59

Verdict: ACCEPTED

input
6
3 2 1 6 4 6 

correct output
14

user output
14

Test 60

Verdict: ACCEPTED

input
7
4 2 1 7 4 7 4 

correct output
17

user output
17

Test 61

Verdict: ACCEPTED

input
10
5 2 1 10 6 10 5 5 5 4 

correct output
31

user output
31

Test 62

Verdict: ACCEPTED

input
3
2 1 3 

correct output
2

user output
2

Test 63

Verdict: ACCEPTED

input
4
3 1 3 4 

correct output
6

user output
6

Test 64

Verdict: ACCEPTED

input
5
3 1 4 5 2 

correct output
7

user output
7

Test 65

Verdict: ACCEPTED

input
6
4 1 5 6 2 1 

correct output
11

user output
11

Test 66

Verdict: ACCEPTED

input
7
4 1 5 6 3 1 4 

correct output
11

user output
11

Test 67

Verdict: ACCEPTED

input
10
10 10 6 2 10 9 8 7 7 6 

correct output
41

user output
41

Test 68

Verdict: ACCEPTED

input
3
3 3 2 

correct output
1

user output
1

Test 69

Verdict: ACCEPTED

input
4
4 4 3 1 

correct output
7

user output
7

Test 70

Verdict: ACCEPTED

input
5
5 5 3 1 5 

correct output
9

user output
9

Test 71

Verdict: ACCEPTED

input
6
6 6 4 2 6 6 

correct output
16

user output
16

Test 72

Verdict: ACCEPTED

input
7
7 7 4 2 7 6 6 

correct output
18

user output
18

Test 73

Verdict: ACCEPTED

input
10
10 10 6 2 10 9 8 7 7 6 

correct output
41

user output
41

Test 74

Verdict: ACCEPTED

input
50
21 50 37 47 1 7 16 50 8 12 5 2...

correct output
764

user output
764

Test 75

Verdict: ACCEPTED

input
50
22 10 2 47 28 48 22 25 22 17 1...

correct output
641

user output
641

Test 76

Verdict: ACCEPTED

input
50
28 4 36 42 15 7 26 29 45 22 45...

correct output
610

user output
610

Test 77

Verdict: ACCEPTED

input
50
49 46 28 9 49 43 36 31 35 30 1...

correct output
783

user output
783

Test 78

Verdict: ACCEPTED

input
250
105 250 181 234 1 33 76 250 37...

correct output
17676

user output
17676

Test 79

Verdict: ACCEPTED

input
250
109 47 7 233 138 237 109 122 1...

correct output
18449

user output
18449

Test 80

Verdict: ACCEPTED

input
250
138 18 178 210 73 31 128 143 2...

correct output
17250

user output
17250

Test 81

Verdict: ACCEPTED

input
250
242 226 137 44 244 214 179 153...

correct output
18157

user output
18157

Test 82

Verdict: ACCEPTED

input
900
376 898 649 840 1 116 273 900 ...

correct output
230450

user output
230450

Test 83

Verdict: ACCEPTED

input
900
393 167 24 839 495 853 392 437...

correct output
230221

user output
230221

Test 84

Verdict: ACCEPTED

input
900
496 64 638 756 262 110 460 513...

correct output
228745

user output
228745

Test 85

Verdict: ACCEPTED

input
900
871 811 493 156 876 771 644 54...

correct output
231686

user output
231686

Test 86

Verdict: ACCEPTED

input
10000
4171 9972 7204 9326 2 1282 302...

correct output
28647603

user output
28647603

Test 87

Verdict: ACCEPTED

input
100000
41703 99721 72034 93258 12 128...

correct output
2838931183

user output
2838931183

Test 88

Verdict: ACCEPTED

input
100000
43601 18509 2593 93156 54968 9...

correct output
2842573127

user output
2842573127

Test 89

Verdict: ACCEPTED

input
100000
55081 7073 70816 83997 29091 1...

correct output
2839271262

user output
2839271262

Test 90

Verdict: ACCEPTED

input
4
100000 100000 100000 100000 

correct output
200000

user output
200000

Test 91

Verdict: ACCEPTED

input
5
100000 100000 100000 100000 10...

correct output
100000

user output
100000

Test 92

Verdict: ACCEPTED

input
6
100000 100000 100000 100000 10...

correct output
300000

user output
300000

Test 93

Verdict: ACCEPTED

input
7
100000 100000 100000 100000 10...

correct output
200000

user output
200000

Test 94

Verdict: ACCEPTED

input
10
100000 100000 100000 100000 10...

correct output
500000

user output
500000

Test 95

Verdict: ACCEPTED

input
50
100000 100000 100000 100000 10...

correct output
2500000

user output
2500000

Test 96

Verdict: ACCEPTED

input
250
100000 100000 100000 100000 10...

correct output
12500000

user output
12500000

Test 97

Verdict: ACCEPTED

input
900
100000 100000 100000 100000 10...

correct output
45000000

user output
45000000

Test 98

Verdict: ACCEPTED

input
10000
100000 100000 100000 100000 10...

correct output
500000000

user output
500000000

Test 99

Verdict: ACCEPTED

input
100000
100000 100000 100000 100000 10...

correct output
5000000000

user output
5000000000

Test 100

Verdict: ACCEPTED

input
3
100000 100000 100000 

correct output
0

user output
0