PROBLEM LINK:
Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4
Setter: Arjun
Tester: Manan Grover, Lavish Gupta
Editorialist: Devendra Singh
DIFFICULTY:
467
PREREQUISITES:
None
PROBLEM:
Most programmers will tell you that one of the ways to improve your performance in competitive programming is to practice a lot of problems.
Our Chef took the above advice very seriously and decided to set a target for himself.
- Chef decides to solve at least 10 problems every week for 4 weeks.
Given the number of problems he actually solved in each week over 4 weeks as P_1, P_2, P_3, and P_4, output the number of weeks in which Chef met his target.
EXPLANATION:
Chef meets his target in a particular week if the number of problems solved by him in that particular week \geq 10. Initialize answer as 0. Iterate over weeks from i =1\: to\: 4 and add 1 to the answer if P_i\geq 10. Output the final value of answer.
TIME COMPLEXITY:
O(1) for each test case.
SOLUTION:
Setter's solution
#include <iostream>
using namespace std;
int main() {
int ans1 = 0;
int a;
for(int i=1;i<=4;i++)
{
cin>>a;
if(a>=10)
ans1++;
}
cout<<ans1<<"\n";
return 0;
}
Editorialist's Solution
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(), _obj.end()
#define F first
#define S second
#define pll pair<ll, ll>
#define vll vector<ll>
const int N = 1e5 + 11, mod = 1e9 + 7;
ll max(ll a, ll b) { return ((a > b) ? a : b); }
ll min(ll a, ll b) { return ((a > b) ? b : a); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void sol(void)
{
int a, b, c, d, ans = 0;
cin >> a >> b >> c >> d;
ans += (a >= 10);
ans += (b >= 10);
ans += (c >= 10);
ans += (d >= 10);
cout << ans;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int test = 1;
// cin>>test;
while (test--)
sol();
}