Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

shriganesh83's blog

By shriganesh83, history, 5 weeks ago, In English,
    • SO, You can solve the problem of "New Year and Hurry". My c++ Solution goes something like this :)

//Using the binary Search to search the exact number of tasks that can be done before leaving for the party :)

Your code here...
#include<bits/stdc++.h>
#include<iostream>
#define in long long
using namespace std;
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    k= 240 &mdash; k;
    k = k/5;
    in c;
    c = n;
    if(c*(c+1)/2 <=k)//&& (c+2)(c+1))
    {
        c = n;
        printf("%lld",c);
        c=-1;
    }
    int l=0,r=n;//This is Lower and Upper Bound
    while( c>=0 )
    {
    c = (l+r)/2; // It is in the middle of upper and lower Bound
    if ((c+2)*(c+1)/2 > k && c*(c+1)/2 <=k)
    {
        //c = c -1;
        printf("%lld",c);
        c=-2;
    }
    else if ( c*(c+1)/2 < k)
    {
         l=c+1;
    }
    else if ( c*(c+1)/2 > k )
    {
         r=c-1;
    }

    }
}

Can someone also tell me how to get this in Editorial of that question Thanks for reading :)

 
 
 
 
  • Vote: I like it
  • -8
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

This is great, but in the future, please use the code formatting feature when creating solution blogs so others can at least read your code.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shriganesh83 (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shriganesh83 (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shriganesh83 (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

You really don't need binary search, I used a simple linear search works in $$$O(n)$$$. I have a variable called "sum" and I stored the total amount of minutes to solve the problems. I also have a counter to store the maximum number of problems that he could do. $$$if(sum + k > 240) break;$$$ because the contest lasts 4 hours. Here is my submission. 75527779

»
5 weeks ago, # |
  Vote: I like it +4 Vote: I do not like it

prog.c:1:1: error: unknown type name ‘Your’