PROBLEM LINK:
Author: Vishesh Saraswat
Tester: Istvan Nagy
Editorialist: Vedant Singh
DIFFICULTY:
CAKEWALK
PREREQUISITES:
Math
PROBLEM:
Given three pairs of Popcorn - Coke combos and duration for which each Popcorn bucket or Coke cup of a combo last, find the maximum duration for which a combo lasts.
QUICK EXPLANATION:
Let the durations for the Popcorn bucket and Coke Cup of the first combo be A_1 and A_2 respectively. Similarly, we can define B_1, B_2, C_1 and C_2. The maximum duration for which a combo lasts is now just the maximum of (A_1+A_2, B_1+B_2, C_1+C_2)
EXPLANATION:
We have to find the maximum duration for which a combo lasts. For the solution, we naively consider all the three cases or combos. We calculate the total duration for each combo, by summing up the durations of the Popcorn bucket and the Coke cup for each combo. Finally, we just find the maximum of these three cases and output it as the answer.
TIME COMPLEXITY:
O(1) for each test case
SOLUTIONS:
Setter's Solution
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int mod = 1e9+7;
void solve(int tc) {
int ans = 0;
for (int i = 0; i < 3; ++i) {
int a, b;
cin >> a >> b;
ans = max(ans, a+b);
}
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
return 0;
}
Tester's Solution
#include <iostream>
#include <algorithm>
#include <string>
#include <cassert>
using namespace std;
#ifdef HOME
#define NOMINMAX
#include <windows.h>
#endif
long long readInt(long long l, long long r, char endd) {
long long x = 0;
int cnt = 0;
int fi = -1;
bool is_neg = false;
while (true) {
char g = getchar();
if (g == '-') {
assert(fi == -1);
is_neg = true;
continue;
}
if ('0' <= g && g <= '9') {
x *= 10;
x += g - '0';
if (cnt == 0) {
fi = g - '0';
}
cnt++;
assert(fi != 0 || cnt == 1);
assert(fi != 0 || is_neg == false);
assert(!(cnt > 19 || (cnt == 19 && fi > 1)));
}
else if (g == endd) {
assert(cnt > 0);
if (is_neg) {
x = -x;
}
assert(l <= x && x <= r);
return x;
}
else {
//assert(false);
}
}
}
string readString(int l, int r, char endd) {
string ret = "";
int cnt = 0;
while (true) {
char g = getchar();
assert(g != -1);
if (g == endd) {
break;
}
cnt++;
ret += g;
}
assert(l <= cnt && cnt <= r);
return ret;
}
long long readIntSp(long long l, long long r) {
return readInt(l, r, ' ');
}
long long readIntLn(long long l, long long r) {
return readInt(l, r, '\n');
}
string readStringLn(int l, int r) {
return readString(l, r, '\n');
}
string readStringSp(int l, int r) {
return readString(l, r, ' ');
}
int main() {
#ifdef HOME
if (IsDebuggerPresent())
{
freopen("../in.txt", "rb", stdin);
freopen("../out.txt", "wb", stdout);
}
#endif
int T = readIntLn(1, 1000);
for (int tc = 0; tc < T; ++tc)
{
int A, B, C, D, E, F;
A = readIntSp(1, 1'000'000'000);
B = readIntLn(1, 1'000'000'000);
C = readIntSp(1, 1'000'000'000);
D = readIntLn(1, 1'000'000'000);
E = readIntSp(1, 1'000'000'000);
F = readIntLn(1, 1'000'000'000);
int res = std::max({ A + B, C + D, E + F });
printf("%d\n", res);
}
assert(getchar() == -1);
}
Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int A1,A2,B1,B2,C1,C2;
cin>>A1>>A2>>B1>>B2>>C1>>C2; // Taking input
int a=A1+A2; // Summing duration
int b=B1+B2; // of popcorn bucket and coke cup
int c=C1+C2; // for each combo
int ans=max(a,max(b,c)); //Calculating max of the three cases
cout<<ans<<"\n";
}
return 0;
}
The event is a part of our annual tech symposium Exun 2021-22, powered by Athena Education.