ALGOCUP2 - Editorial

PROBLEM LINK:

Practice
AlgoCup Contest

Author: Sobhagya singh dewal
Tester: Sankalp Gupta

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Greedy, Math

PROBLEM:

Minimum length subsequence with maximum product possible

QUICK EXPLANATION:

Take all numbers greater than 1, according to constraints all numbers in array are greater than or equal to 0 and at least 1 number will be positive so if there is no number greater than 1 then just print 1 1, else print count of numbers greater than 1 and minimum among numbers greater than 1.

EXPLANATION:

According to the question if we check constraints we get to know that all numbers in the array are greater than or equal to 0, and there will be at least 1 positive integer.
In the question it is mentioned that first we need to take a booster and assign it to power, so basically we must take an integer greater than 0.
And we know that k*a > a if k>1, so basically we take all numbers greater than 1, take count and minimum among them
So now we have two cases:
Count of numbers greater than 1 is zero : In this case we will sure find 1 somewhere in array so just print 1 1.
Count of numbers greater than 1 is non-zero : Print count and minimum number among them.

SOLUTIONS:

Setter’s Solution
#include<bits/stdc++.h>
int mod=1e9+7; 
using namespace std;

int32_t main()
{
  int tt;
  cin>>tt;
  while(tt--)
  {
      int n; cin>>n;
      int one=0,other=0,mi=mod;
      for(int i=0;i<n;i++)
       {
          int a; cin>>a;
          if(a==1)
            one++;
          if(a>1)
          {
              other++;
              mi=min(mi,a);
          }
      }
      if(other==0)
      {
          cout<<"1 1\n";
      }
      else
        cout<<other<<" "<<mi<<"\n";
       }
  }
Tester's Solution
#include<bits/stdc++.h>  
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvl vector<vll> 
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii >
#define vpll vector<pll >
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define fastio ios_base::sync_with_stdio(false) , cin.tie(NULL) ,cout.tie(NULL)
ll power(ll a,ll b){ ll res=1; while(b>0){ if(b&1) res*=a; a*=a; b>>=1;} return res; }
ll power(ll a,ll b,ll m){ ll res=1; while(b>0){ if(b&1) res=(res*a)%m; a=(a*a)%m; b>>=1;} return res;}
bool pp(int a,int b) {return a>b;}
using namespace std;

void solve(){
 int n;
 cin>>n;
 assert(n>=1&&n<=10000);
 int a[n+1];
 for(int i=0;i<n;i++)cin>>a[i],assert(a[i]>=0&&a[i]<=10000000);


 int c=0,an=1e9;
 for(int i=0;i<n;i++){

    if(a[i]>1)
    c++,an=min(a[i],an);
}
if(c==0)
c=1,an=1;

cout<<c<<" "<<an<<"\n";
}

int main()
{
 fastio;
 int t;
 cin>>t;
 assert(t>=1&&t<=1000);
 while(t--){
    solve();
  }

   return 0;
 }
1 Like