Question: Airtel, Recent Online Assessment Questions | Weird Number | Maximizing the Array
2
Entering edit mode

ADD COMMENTlink 11 months ago PoGo 2.3k
0
Entering edit mode

// weird number

#include<bits/stdc++.h>
using namespace std;

#define ll long long

ll func(ll i, ll curr, ll sum, ll k, ll bounded, vector<ll> &vect) {
if(i==vect.size()) {
if(curr%k!=0 && sum%k==0) return 1;
return 0;
}
ll res=0;
if(bounded) {
for(ll j=0;j<vect[i];j++) {
res+=func(i+1, curr*10+j, sum+j, k, 0, vect);
}
res+=func(i+1, curr*10+vect[i], sum+vect[i], k, 1, vect);
}
else {
for(ll j=0;j<=9;j++) {
res+=func(i+1, curr*10+j, sum+j, k, 0, vect);
}
}

return res;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll n,k;cin >> n >> k;
ll temp=n;
vector<ll> vect;
while(temp) {
vect.push_back(temp%10);
temp/=10;
}
reverse(vect.begin(), vect.end());
cout << func(0, 0, 0, k, 1, vect);

return 0;
}
ADD COMMENTlink 11 months ago sumeet kumar sahoo • 290
0
Entering edit mode

// maximizing the array

// im assuming that the constraings are 0 < n <10^6, 0 < n < 10^6. because its impossible the make array of size 10^9

#include<bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,m;cin >> n >> m;

vector<int> v1(n);for(int i=0;i<n;i++) cin >> v1[i];
vector<int> v2(m);for(int i=0;i<m;i++) cin >> v2[i];

sort(v2.begin(), v2.end(), greater<int>());

int i=0,j=0;

while(i<n && j<m) {
if(v2[j]>v1[i]) {
swap(v1[i],v2[j]);
j++;
}
i++;
}

for(auto var:v1) cout << var << " ";

return 0;
}
ADD COMMENTlink 11 months ago sumeet kumar sahoo • 290
0
Entering edit mode
``````void solve()
{
ll n ,m ; cin >> n>> m ;
vll a(n) ,b(m) ;
fl(i ,0 ,n )cin >> a[i] ;
fl(i ,0 ,m )cin >> b[i] ;

sort(rbegin(b), rend(b)) ;
ll j= 0 ;
fl(i ,0 ,n )
{
if(j<m &&  a[i]<b[j])
{
a[i]= b[j++] ;
}
}
for(auto it: a )
{
cout << it << " " ;
}

}
``````

ADD COMMENTlink 11 months ago Kshitiz Kumar • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts