We'd like to thank you all for participating in the contest, and hope you enjoyed it. Hope to see you again soon!
Author: JainWinn
Just calculate length of longest subarray containing only $$$7$$$ .
#include<bits/stdc++.h>
using namespace std;
//=======================================================================
#define ll long long
#define int long long
#define vi vector<int>
#define endl '\n'
void solve(){
int n;
cin>>n;
vi a(n,0);
for(int i=0 ; i<n ; i++){
cin>>a[i];
}
int maxi=0;
for(int i=0 ; i<n ; i++){
int curr=0;
while(i<n && a[i]==7){
curr++;
i++;
}
maxi=max(maxi,curr);
}
cout<<maxi<<endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
Author: JainWinn
Given $$$n$$$ poles and each pole can be used at most $$$k$$$ times , the answer is simply $$$(n*k)/3$$$ if $$$n \gt 2$$$ and $$$0$$$ otherwise . We can treat each pole as collection of $$$k$$$ poles such that our selection of poles for each triangle ensure that each pole belongs to different pole collection .
#include<bits/stdc++.h>
using namespace std;
//=======================================================================
#define int long long
#define endl '\n'
void solve(){
int n,k;
cin>>n>>k;
if(n<3){
cout<<0<<endl;
return;
}
cout<<(n*k)/3<<endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
Author: JainWinn
This problem can be solved using priority queue or ordered set. Sort vector/pair of start and end time of examinations by start time. Sort pair/vector of invigilation time and it's index by invigilation time. Now iterating through each invigilation time in increasing order, we can calculate number of students invigilated using priority queue or ordered set. Push the end times of those examinations in min priority queue whose start time is smaller than or equal to current invigilation time. Now pop those examination end times from priority queue which are smaller than current invigilation time. The size of priority queue gives number of students invigilated for current invigilation time. This can also be done using ordered set. The problem can also be solved using line sweeping technique, but I leave this task on the participants to do it by themselves.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
template <class T> using pbds = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//=======================================================================
#define ll long long
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
void printarray(vector<int> &a){
for(int i=0 ; i<(int)a.size() ; i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
void solve(){
int n;
cin>>n;
vi st(n,0);
for(int i=0 ; i<n ; i++){
cin>>st[i];
}
vi ed(n,0);
for(int i=0 ; i<n ; i++){
cin>>ed[i];
}
int m;
cin>>m;
vpi t;
for(int i=0 ; i<m ; i++){
int x;
cin>>x;
t.pb(make_pair(x,i));
}
vvi s;
for(int i=0 ; i<n ; i++){
s.pb({st[i],ed[i]});
}
sort(all(s));
sort(all(t));
int itr=0;
vi ans(m,0);
priority_queue<int,vector<int>,greater<int>> exam;
for(int i=0 ; i<m ; i++){
while((itr<n) && (s[itr][0] <= t[i].ff)){
exam.push(s[itr][1]);
itr++;
}
while(!exam.empty() && exam.top()<t[i].ff){
exam.pop();
}
int curr=exam.size();
ans[t[i].ss]=curr;
}
printarray(ans);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
template <class T> using pbds = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//=======================================================================
#define ll long long
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
void printarray(vector<int> &a){
for(int i=0 ; i<(int)a.size() ; i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
void solve(){
int n;
cin>>n;
vi st(n,0);
for(int i=0 ; i<n ; i++){
cin>>st[i];
}
vi ed(n,0);
for(int i=0 ; i<n ; i++){
cin>>ed[i];
}
int m;
cin>>m;
vpi t;
for(int i=0 ; i<m ; i++){
int x;
cin>>x;
t.pb(make_pair(x,i));
}
vvi s;
for(int i=0 ; i<n ; i++){
s.pb({st[i],ed[i],i});
}
sort(all(s));
sort(all(t));
int itr=0;
vi ans(m,0);
pbds<pair<int,int>> exam;
for(int i=0 ; i<m ; i++){
while((itr<n) && (s[itr][0] <= t[i].ff)){
exam.insert({s[itr][1],s[itr][2]});
itr++;
}
int curr=exam.order_of_key({t[i].ff,-1});
ans[t[i].ss]=itr-curr;
}
printarray(ans);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}



