Friday, August 12, 2022

Codeforces 750A - New Year and Hurry

Problem Link - https://codeforces.com/contest/750/problem/A

Editorial

Do you see what is produced by the following piece of code?

int total = 0;
for(int i = 1; i <= n; ++i) {
	total += 5 * i;
	printf("%d\n", total);
}

We iterate over problems (a variable i denotes the index of problem) and in a variable total we store the total time needed to solve them. The code above would print numbers 5, 15, 30, 50, ... — the i-th of these numbers is the number of minutes the hero would spend to solve easiest i problems.

Inside the loop you should also check if there is enough time to make it to the party, i.e. check if total + k <= 240.

Solution

        
    #include<bits/stdc++.h>
    using namespace std;

    int main()
    {  
    int n,k; int count=0; int sum=0;
    cin>>n>>k;

    for(int i=1; i<=n; i++)
    {
        sum += 5*i;  
        if(sum>240-k) break;
        count +=1;
    }
    cout<<count<<endl;
    return 0;
    }

No comments:

Post a Comment