u/Low-Decision-6017

Advise for cp mindset

Hi,i solved around 300 questions on cf and mostly between 1200 and 1500,and my current rating is 1100 (max rated 1200),in today's contest i was able to solve only a, and solved b and c within 10 min after the contest,the main problem with me is i have a lot of anxiety when the contest is running and I'm unable to think under pressure,my mindset throughout the contest was to solve the questions as fast as possible,and i think i have the wrong mindset,any advice from seniors about mindset would be very grateful,what should be the mindset in cp and while giving the contest ?

reddit.com
u/Low-Decision-6017 — 1 day ago

Easiest solution for edu 192,b

Calculate the prefix sum for all indices using logic +1 for 1, -1 for 2 and 3.

Now iterate from backwards and calculate the suffix sum using logic +1 for 1 and 2, -1 for 3,and also maintain a mn,which tells us the min suf sum found from index i+1 to n-1,at any point,pre[i -1]> 0 and suf - mn >=0,we got the answer and we can print yes,if not do it till index 1,if no index satisfies this condition cout no.

Think why the ( suf - mn >= 0) logic works,its just the sum of subarray.from 0 till i - 1 is the part 1,i to mn -1 is second part and mn to n -1 is the third part.

Code

void solution(){

int n;

cin >> n;

vector<int> s(n);

for(int i = 0; i < n; i++) cin >> s[i];

vector<int> pre(n + 1,0);

pre[0] = (s[0] == 1) ? 1 : -1;

for(int i = 1; i < n; i++) pre[i] = pre[i - 1] + ((s[i] == 1) ? 1 : -1);

int sum = 0;

int mn = 1e8;

for(int i = n - 1; i > 0; i--){

sum += ((s[i] == 3) ? -1 : 1);

if(pre[i - 1] >= 0){

if(sum - mn >= 0){

cout<<"YES"<<endl;

return;

}

}

mn = min(mn,sum);

}

cout<<"NO"<<endl;

}

reddit.com
u/Low-Decision-6017 — 1 day ago