GOODWEAT - Editorial

PROBLEM LINK:

Practice
Div1
Div2
Div3

Setter: Soumyadeep Pal
Tester: Manan Grover
Editorialist: Ajit Sharma Kasturi

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

The weather of 7 days in a week is represented by an array A of 7 integers with values 0 and 1, where A_i=1 denotes that day i is a sunny day and A_i=0 denotes that day i is a rainy day. The weather report is said to be good if the number of sunny days is strictly greater than the number of rainy days. If the weather report is good, we have to output “YES” else we have to output “NO” (without quotes).

EXPLANATION:

Let us consider two integer variables sunny and rainy which denotes the total number of sunny and rainy days respectively. Both these variables are initialized to 0. We will then iterate over i from 1 to 7, if A_i=1 increment sunny by 1 else increment rainy by 1.

Now, if sunny \gt rainy, we output “YES” else we output “NO”.

TIME COMPLEXITY:

O(1) for each testcase.

SOLUTION:

Editorialist's solution
#include <bits/stdc++.h>
using namespace std;

int main()
{
     int tests;
     cin >> tests;
     while (tests--)
     {
          vector<int> is_sunny(7);
          for (int i = 0; i < 7; i++)
               cin >> is_sunny[i];

          int tot_sunny = 0, tot_rainy = 0;
          for (int i = 0; i < 7; i++)
          {
               if (is_sunny[i])
                    tot_sunny++;
               else
                    tot_rainy++;
          }

          if (tot_sunny > tot_rainy)
               cout << "YES" << endl;
          else
               cout << "NO" << endl;
     }
     return 0;
}

Setter's solution
#include<bits/stdc++.h>
using namespace std;


void solve(int tc) {
  int sum = 0;
  for (int i = 0; i < 7; i++) {
    int x; cin >> x;
    sum += x;
  }
  if (sum > 3) cout << "YES\n";
  else cout << "NO\n";
}
signed main() {
  ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) solve(i);
  return 0;
}



Tester's solution
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
    int cnt = 0;
    int temp;
    for(int i = 0; i < 7; i++){
      cin>>temp;
      if(temp){
        cnt++;
      }else{
        cnt--;
      }
    }
    if(cnt > 0){
      cout<<"YES\n";
    }else{
      cout<<"NO\n";
    }
  }
  return 0;
}

Please comment below if you have any questions, alternate solutions, or suggestions. :slight_smile: