×

# Calvins Game (Can Someone Tell Me What Am I Missing)

// https://www.codechef.com/INOIPRAC/problems/INOI1301

# include <bits stdc++.h="">

using namespace std;

# define ll long long

int main() { ll n,k,tSum= -2000 ,tSum2=-2000,sumMax=-2000,eIndex=0; cin >> n >> k; ll arr[n],arrTemp[n],arrTemp2[n]; eIndex = k-1; for(ll i=0;i<n;i++) {="" cin="">> arr[i]; arrTemp[i] = arr[i]; arrTemp2[i] = arr[i]; } for(ll i=k; i<n;i++) {="" if(i="">k+1) { arrTemp[i] += max(arrTemp[i-1],arrTemp[i-2]); } else if(i == k+1) { arrTemp[i] += max(arrTemp[k],(ll) 0); } if(arrTemp[i] > tSum) // think about equal to { tSum = arrTemp[i]; eIndex = i; } } // eIndex is where we are at right now and tSum has the current max sum for(ll i=eIndex-1; i >= 0;i--) { if(i < eIndex-2) { arrTemp2[i] += max(arrTemp2[i+1],arrTemp2[i+2]); } else if(i == eIndex-2) { arrTemp2[i] += max(arrTemp2[eIndex-1],(ll) 0); } } tSum2 = arrTemp2[0];

for(ll i=k-2; i >= 0;i--)

{ if(i < k-3) { arr[i] += max(arr[i+1],arr[i+2]); } else if(i == k-3) { arr[i] += max(arr[k-2],(ll) 0); } } sumMax = arr[0]; sumMax = max(tSum+tSum2,sumMax); if(k-1 == 0) { sumMax = max(sumMax,(ll) 0); } cout << sumMax;
return 0; }
//The Code Failed On 6 Tasks Out Of 17, If Someone Can Take the Time To Go Through This

//And Explain What Am I Doing Wrong, I Will Be Very Thankful.

0★mg1_23
1
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,739
×218
×140
×1