Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Codechef/Codeshef-January-2021-solutions/ANTSCHEF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--)
{
int n;
cin>>n;
int m;
cin>>m;
long long int a[m];
for (int i=0;i<m;i++)
{
cin>>a[i];
}
long long int cntneg=0, cntpos=0, sum=0;
if(n==1)
{
sort(a,a+m);
if(a[0]>0)cout<<0<<endl;
else if(a[m-1]<0) cout<<0<<endl;
else
{
for(int i=0;i<m;i++)
{
if(a[i]>0){cntneg=i;cntpos=m-i;break;}
}
while (cntneg>0 && cntpos>0)
{
sum = sum + cntneg+cntpos -1;
cntneg --;
cntpos --;
}
cout<<sum<<endl;
}
}
}

return 0;
}
49 changes: 49 additions & 0 deletions Codechef/Codeshef-January-2021-solutions/BILLRD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <bits/stdc++.h>

using namespace std;

#define ll long long



int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

int t;
cin>>t;
while(t--){
int n,k,x,y;

cin>>n>>k>>x>>y;
map<int,int>m;
m.insert(pair<int, int>(x, y));

if(x==y){
cout<<n<<" "<<n<<endl;

}
else{
vector<pair<int,int>>vect;
if(x<y){
int a[]={x+n-y,n,y-x,0};
int b[]={n,n-y+x,0,y-x};
for (int i=0; i<4; i++)
vect.push_back( make_pair(a[i],b[i]) );
}else{
int c[]={n,y+n-x,0,x-y};
int d[]={y+n-x,n,x-y,0};
for (int i=0; i<4; i++)
vect.push_back( make_pair(c[i],d[i]) );
}


int x=(k-1)%4;
cout<<vect[x].first<<" "<<vect[x].second<<endl;

}

}


}
42 changes: 42 additions & 0 deletions Codechef/Codeshef-January-2021-solutions/DECODEIT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>

using namespace std;

#define ll long long


ll convert(string s) {
ll n=stoi(s);

ll dec = 0, i = 0, rem;
while (n != 0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}
return dec;
}



int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
char a [16] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
ll t,n,num;
string s,s1;
// char a [16] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
cin>>t;
while(t--){
cin>>n;
cin>>s;
for(int i=0;i<n;i=i+4){
s1=s.substr(i,4);
num=convert(s1);
cout<<a[num];
}
cout<<endl;
}
// delete a;
}
42 changes: 42 additions & 0 deletions Codechef/Codeshef-January-2021-solutions/DIVTHREE.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>

using namespace std;

#define ll long long



int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

int t,n,k,d,p,sum;
cin>>t;
while(t--){
cin>>n>>k>>d;
sum=0;


for(int i=0;i<n;i++){
cin>>p;
sum+=p;
}

if(sum<k)
{
cout<<"0"<<endl;

}
else{

sum=ceil(sum/k);

cout<<min(sum,d)<<endl;
}


}
return 0;


}
59 changes: 59 additions & 0 deletions Codechef/Codeshef-January-2021-solutions/FAIRELCT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <bits/stdc++.h>

using namespace std;

#define ll int




int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

int t;
cin >>t;
while(t--){
int size1;
int size2;
cin>>size1>>size2;
int* arr1=new int[size1];
int* arr2=new int[size2];
int sum1=0,sum2=0;
for(int i=0;i<size1;i++){
cin>>arr1[i];
sum1+=arr1[i];
}
for(int i=0;i<size2;i++){
cin>>arr2[i];
sum2+=arr2[i];
}
if(sum1>sum2){
cout<<"0"<<endl;
continue;
}

sort(arr1,arr1+size1);
sort(arr2,arr2+size2);
int count=0;
int j=size2-1;
for(int i=0;i<size1;i++){
sum1=sum1-arr1[i]+arr2[j];
sum2=sum2-arr2[j]+arr1[i];
//sum1=sum1+arr2[j];
//sum2=sum2+arr1[i];
count++;
j--;
if(sum1>sum2 || j<0){
break;
}
}
if(sum1>sum2){
cout<<count<<endl;
}else{
cout<<"-1"<<endl;
}
}
return 0;

}
93 changes: 93 additions & 0 deletions Codechef/Codeshef-January-2021-solutions/WIPL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

ll result(ll x,ll a[],ll n){
int pos[x+1]={'\0'};
pos[0]=1;
for(int i=0;i<n;i++)
for(int j=x;j>=a[i];j--){
if(pos[j-a[i]]==1)
pos[j]=1;
}
return pos[x];
}

void solve(){
ll n,k;
cin>>n>>k;
ll sum=0,ans=0;
ll a[n]={'\0'};

for(ll i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}

sort(a,a+n,greater<>());

if(n==1 || sum<2*k){
cout<<"-1\n";
return;
}

else if(sum==2*k){

if(sum%2==1 || a[0]>k){
cout<<"-1\n";
return;
}
else if(a[0]==k){
cout<<n<<"\n";
}

else{

if(result(k,a,n)){
cout<<n<<"\n";
return;
}
else{
cout<<"-1\n";
return;
}
}
}

else if(a[0]>=k){
ans =1;
ll tempsum=0;
for(ll i=1;i<n;i++){
tempsum+=a[i];
ans++;
if(tempsum>=k){
cout<<ans<<"\n";
return ;
}

}
}

else{
ll tempsum=0;
for(ll i=0;i<n;i++){
tempsum+=a[i];
if(tempsum>=2*k){
cout<<i+1<<"\n";
return;
}
}
cout<<"-1\n";
}

}


int main(){
ll t;
cin>>t;
while(t--){
solve();
}
}