Spoilers are broken! Sorry for the inconvenience!
Introduction
The contest can be found here
This is an unofficial editorial and I am no way associated to Vplanet!
. Also this is my second ever blog on first code forces , and I have tried to replicate many editorial blogs as far as possible, but if I have made any mistake , please do let me know :D
Problem A Arya and Bran
We notice that the maximum amount of candies that we can give is 8 the rest of the candies are carry forward to the next day
So more formally , the tofees given on day i is min(arr[i],8)
and the number of candies carry forward are max(0,arr[i]-8).
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define debug(x) cout << (#x) << "'s value is " << (x) << newl
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin); // see /general/io
freopen((name+".out").c_str(), "w", stdout);
}
}
// Main code starts here
void answer(int i){
int n,k;
cin>>n>>k;
int arr[n];
int sumn = 0;
for(int i = 0;i<n;i++){
cin>>arr[i];
}
for(int i = 0;i<n;i++){
int taken = min(8,arr[i]);
int put = max(0,arr[i]-8);
arr[i+1]+=put;
sumn+=taken;
if(sumn>=k){
cout<<i+1;
break;
}
}
if(sumn<k){
cout<<"-1"<<newl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
____________________________________________________________________________________
Problem B Love Triangle
For this problem we can directly check that there is a triangle formed , by the numbers written on the array and then print the answer accordingly
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define debug(x) cout << (#x) << "'s value is " << (x) << newl
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin); // see /general/io
freopen((name+".out").c_str(), "w", stdout);
}
}
// Main code starts here
void answer(int i){
int n;
cin>>n;
int arr[n];
for(int i = 0;i<n;i++){
cin>>arr[i];
}
for(int i = 0;i<n;i++){
int lol = arr[i];
int lol2 = arr[lol-1];
int lol3 = arr[lol2-1];
if(lol3 == i+1){
cout<<"YES";
return;
}
}
cout<<"NO";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
____________________________________________________________________________________
Problem C — Chess for three
So for this problme we need to know the following details , the person who is watching , and the players who are playing , if the winner is the spectator at any point of time then the game is not possible or else its possible.
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define debug(x) cout << (#x) << "'s value is " << (x) << newl
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin); // see /general/io
freopen((name+".out").c_str(), "w", stdout);
}
}
// Main code starts here
void answer(int i){
int n;
cin>>n;
int player1 = 1;
int player2 = 2;
int coming_up = 3;
for(int i = 0;i<n;i++){
int a;
cin>>a;
if(player1==a || player2==a){
if (player2==a){
swap(player1,coming_up);
}
else{
swap(player2,coming_up);
}
}
else{
cout<<"NO";
return;
}
}
cout<<"YES";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
____________________________________________________________________________________
D. Fafa and his Company
We can run a loop from the 1 to the number given and check if (number-i)%i == 0 as it is the only way that all the leaders have same number of people working under them.
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define debug(x) cout << (#x) << "'s value is " << (x) << newl
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin); // see /general/io
freopen((name+".out").c_str(), "w", stdout);
}
}
// Main code starts here
void answer(int test){
int n;
cin>>n;
int answer = 0;
for(int i = 1;i<n;i++){
if((n-i)%i==0){
answer++;
}
}
cout<<answer;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
____________________________________________________________________________________
E. Restaurant Tables
In this problem we can take in input and check if the person is 2 seater or one seater , then if a person is two seater then we check if we have a two seater left , else we disappoint 2 customers. If its a one seater and we donot have a 1 seater left but we have a 2 seater left ,then we can put the one person there are increase the count of one seater as now anathor one person can sit with him
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define debug(x) cout << (#x) << "'s value is " << (x) << newl
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin); // see /general/io
freopen((name+".out").c_str(), "w", stdout);
}
}
// Main code starts here
void answer(int test){
int n;
cin>>n;
int answer = 0;
for(int i = 1;i<n;i++){
if((n-i)%i==0){
answer++;
}
}
cout<<answer;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
____________________________________________________________________________________
F. Between the Offices
We can see the number of times the person moves from S to F and from F to S and then depending depending on the cound check if we have to print no or yes
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define debug(x) cout << (#x) << "'s value is " << (x) << newl
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin); // see /general/io
freopen((name+".out").c_str(), "w", stdout);
}
}
// Main code starts here
void answer(int i){
int a;
cin>>a;
string b;
cin>>b;
int noooo = 0;
int yees = 0;
char curr = b[0];
for(int i = 1;i<a;i++){
char lol = b[i];
if(curr=='F' && lol=='S'){
noooo++;
}
if(curr=='S' && lol=='F'){
yees++;
}
curr = lol;
}
if(yees>noooo){
cout<<"YES"<<newl;
}
else{
cout<<"NO"<<newl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}