PROBLEM LINK:
Author: Digvijay Janartha
Tester: Chandan Boruah
Editorialist: Gaurav Jaiswal
DIFFICULTY:
CAKEWALK
PREREQUISITES:
BASIC OBSERVATION
EXPLANATION:
If n is 1, then only one apple is required, we can not use orange or watermelon to make
the energy exactly equal to n.So answer for this case is “1 1”.
If n is not 1. Then there can be two cases:
- If n is even:
In this case, first we have to minimize number of apples, so we can select 0 apples,
then to maximize total number of fruits we can select n/2 orange such that (2*n/2 = n).
Since, watermelon increases energy by 3 units, so we can not use this. - If n is odd:
In this case,To maximize total number of fruits we can take (n-1)/2 orange and 1 apple,
but first we have to minimize total number of apple. So we try to take number of apple as 0.
So now we can take (n-3)/2 orange and 1 watermelon.
For both the cases number of apple=0
total number of fruits=(n-1)/2
TIME COMPLEXITY:
O(1)
SOLUTIONS:
Setter's Solution
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
int len = comma - names;
for (int i = 0; i < len; ++i) {
cout << names[i];
}
cout << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void test();
int main() {
fast_io();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cout << fixed << setprecision(15);
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
test();
}
#ifndef ONLINE_JUDGE
cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
#endif
return 0;
}
void test() {
int n;
cin >> n;
if (n == 1) {
cout << "1 1\n";
} else {
cout << "0 " << n / 2 << "\n";
}
}
Tester's Solution
using System;
class some
{
public static void Main()
{
int t=int.Parse(Console.ReadLine());
while(t-- >0)
{
int n=int.Parse(Console.ReadLine());
int count=0;
int kk=n/2;
int pp=n%2;
if(pp==1)
{
if(n-3>=0)
{
kk=(n-3)/2;
count=1+kk;
Console.WriteLine(0+" "+count);
}
else
{
if(n==1)Console.WriteLine(1+" "+1);
}
}
else
{
Console.WriteLine(0+" "+kk);
}
}
}
}