You are not logged in. Please login at www.codechef.com to post your questions!

×

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.

asked 17 Feb, 08:00

mg1_23's gravatar image

0★mg1_23
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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

question asked: 17 Feb, 08:00

question was seen: 43 times

last updated: 17 Feb, 08:00