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 .
- Each of the remaining bells will increase her mana level by .
- As a bonus, once the final bell is rung, her mana level will increase by a further .
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
Sample 1:
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 , the first two bells provide to it, and the next provide to it.
Test case : No bells were rung, so the mana level remains at .
Test case : One bell was rung, so the mana level is
Test case : Four bells were rung, so the mana level is
Test case : All bells were rung, so the mana level is .
Note that the extra is a bonus for ringing all the bells; the last bell still provides 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
6 2 0 80
6 2 1 80
6 2 4 80
6 2 6 80
Output
90
110
140
Demonstration
CodeChef solution PILBELLS - Bells of Pilgrimage Codechef solution in C,C++