/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 576.0 KiB
#2 Accepted 2ms 576.0 KiB
#3 Accepted 1ms 584.0 KiB
#4 Accepted 2ms 576.0 KiB
#5 Accepted 28ms 580.0 KiB
#6 Accepted 39ms 11.082 MiB
#7 Accepted 39ms 11.207 MiB
#8 Accepted 39ms 11.223 MiB
#9 Accepted 36ms 11.121 MiB
#10 Accepted 36ms 11.195 MiB
#11 Accepted 36ms 11.082 MiB
#12 Accepted 36ms 11.082 MiB
#13 Accepted 36ms 11.207 MiB
#14 Accepted 36ms 11.039 MiB
#15 Accepted 36ms 11.156 MiB
#16 Accepted 36ms 11.145 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int mx = 1e5 + 5 ;
ll n , a[mx] , b[mx] , c[mx] , dp[mx][3];
ll heart(ll pos , int arr){
   if(pos > n) return 0 ;
   if(dp[pos][arr] != -1) return dp[pos][arr] ;
   ll res = INT_MIN ;
   if(arr == 0) {
    res = max(res , heart(pos + 1 , 1) + b[pos]) ;
    res = max(res , heart(pos + 1 , 2) + c[pos]) ;
   }

   else if(arr == 1) {
    res = max(res , heart(pos + 1 , 0) + a[pos]) ;
    res = max(res , heart(pos + 1 , 2) + c[pos]) ;
   }

   else {
    res = max(res , heart(pos + 1 , 1) + b[pos]) ;
    res = max(res , heart(pos + 1 , 0) + a[pos]) ;
   }
   return dp[pos][arr] = res ;

}
void solve()
{
   cin >> n ;
   for(int i = 1 ; i <= n ; i++) cin >> a[i] ;
   for(int i = 1 ; i <= n ; i++) cin >> b[i] ;
   for(int i = 1 ; i <= n ; i++) cin >> c[i] ;
   for(int i = 1 ; i <= n ; i++) dp[i][0] = dp[i][1] = dp[i][2] = -1;
   cout << max({heart(1 , 0) ,heart(1 , 1), heart(1 , 2)}) << endl ;


}
int main()
{
     __Heart__
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1046 Maximum sum in 3-array
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-26 01:16:22
Judged At
2024-11-11 03:40:20
Judged By
Score
100
Total Time
39ms
Peak Memory
11.223 MiB