Algorithm


 problem Link :  https://www.codechef.com/START96D/problems/PILBELLS

Problem

The Child of Prophecy has embarked on a journey to save the land of the Fae.
On her journey, she must ring  Bells of Pilgrimage.

The Child of Prophecy has an initial mana level of . After that:

  • Each of the first  bells she rings will increase her mana level by 10.
  • Each of the remaining bells will increase her mana level by 5.
  • As a bonus, once the final bell is rung, her mana level will increase by a further 20.

 bells have been rung so far. What is the current mana level of the Child of Prophecy?

Input Format

  • The first line of input will contain a single integer , denoting the number of test cases.
  • Each test case consists of a single line of input, containing four space-separated integers , and  — as described in the statement.

Output Format

For each test case, output on a new line a single integer: the Child of Prophecy's current mana level.

Constraints

  • 1≤�≤100
  • 1≤�<�≤105
  • 0≤�≤�
  • 0≤�≤105

Sample 1:

Input
 
Output
 
4
6 2 0 80
6 2 1 80
6 2 4 80
6 2 6 80
80
90
110
140

Explanation:

In all sample test cases, the initial mana level is 80, the first two bells provide +10 to it, and the next 4 provide +5 to it.

Test case 1: No bells were rung, so the mana level remains at 80.

Test case 2: One bell was rung, so the mana level is 80+10=90

Test case 3: Four bells were rung, so the mana level is 80+10+10+5+5=110

Test case 4: All bells were rung, so the mana level is 80+10+10+5+5+5+5+20=140.
Note that the extra 20 is a bonus for ringing all the bells; the last bell still provides +5 on its own.

Code Examples

#1 Code Example with C Programming

Code - C Programming

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

void solve()
{
    int n,x,k,p;
    cin>>n>>x>>k>>p;
    for(int i=1; i < =k; ++i)
    {
        if(i<=x) p=p+10;
        else p=p+5;
        if(i==n) p=p+20;
    }
    cout<<p<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int TC = 1;
    cin >> TC;
    cin.ignore();
    while (TC--) solve(>;
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
6 2 0 80
6 2 1 80
6 2 4 80
6 2 6 80

Output

x
+
cmd
80
90
110
140
Advertisements

Demonstration


CodeChef solution PILBELLS  - Bells of Pilgrimage Codechef solution  in C,C++

Previous
CodeChef solution WEEDING - Weeding Codechef solution in C,C++
Next
Codechef solution ABDIFF - AB Difference Codechef solution in C,C++