Skip to content

added Codeforces Round #667 (Div. 3) Problem-A solution #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
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
54 changes: 54 additions & 0 deletions CodeChef_problems/ChefinaAndSwaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
Problem Link - https://www.codechef.com/JULY20B/problems/CHFNSWPS
'''

from sys import *
from math import *
from collections import *

mod = 1000000007

def get_array(): return list(map(int, stdin.readline().split()))

def get_ints(): return map(int, stdin.readline().split())

def get_int(): return int(stdin.readline())

def get_input(): return stdin.readline().strip()

def main():
tc = get_int()
while(tc):
N = get_int();arr = get_array();arr1 = get_array()
mini = min(min(arr),min(arr1))
counter = Counter(arr+arr1)
set,dic,dic1 = 0,{},{}
for i in counter:
if counter[i]&1:set = 1;break
else:
dic[i] = counter[i]/2
if set:stdout.write("-1\n");
else:
dic1,list1,list2 = dic,[],[]
for i in range(N):
if dic[arr[i]]:
dic[arr[i]] -= 1
else:
list1.append(arr[i])
for i in range(N):
if dic1[arr1[i]]:
dic1[arr1[i]] -= 1
else:
list2.append(arr1[i])
list1.sort();list2.sort(reverse=True)
length = len(list1)
if length==0:stdout.write('0\n')
else:
ans = 0
for i in range(length):
ans += min(2*mini,min(list1[i],list2[i]))
stdout.write(str(ans) + '\n')
tc-=1

if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions CodeChef_problems/Long_contest_and_cook_off_overlaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
t = int(input())
year = [0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 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, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0]

for _ in range(t):
m1,y1 = map(int,input().split())
m2,y2 = map(int,input().split())
if(m1<=2):
y1-=1
if(m2<2):
y2-=1
value1 = (y1//400)*101 + sum(year[:y1%400])
value2 = (y2//400)*101 + sum(year[:y2%400])
print(value2 - value1)
28 changes: 28 additions & 0 deletions CodeChef_problems/expected_change.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def fun(s):
ans = 0
o = 0
c = 0
for i in s:
if(i=="("):
o+=1
elif(i==")"):
c+=1
if(c>o):
c-=1
o+=1
ans+=1
return ans

t = int(input())

for _ in range(t):
n = int(input())
s = input()
ans = 0
N = 10**9+7
value = ((n+1)*n)//2
value = pow(value,N-2,N)
print(value)
for i in range(n):
ans+=fun(s[i:])
print((ans*value)%N)
72 changes: 72 additions & 0 deletions CodeChef_problems/the_theatre_problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# def fun(mymatrix,col,row,xvalue):
# ans = 0
# maximum = 0
# #itration 1
# for i in range(4):
# if(row[i]==1):
# for j in range(4):
# if(col[j]==1):
# if(mymatrix[i][j]>maximum):
# maximum = mymatrix[i][j]
# if(maximum==0):
# ans-=(5-xvalue)*100
# return ans
# ans+=maximum*(5*xvalue)*25
# value = []
# for i in range(4):
# flag = 0
# if(row[i]==1):
# for j in range(4):
# if(col[j]==1):
# if(mymatrix[i][j]==maximum):
# col[j] = 0
# row[i] = 0
# value.append(fun(mymatrix,col,row,xvalue+1))
# col[j] = 1
# row[i] = 1

# return ans + max(value)

t = int(input())
myans = 0
for _ in range(t):
n = int(input())
# col = [1 for i in range(4)]
# row = [1 for i in range(4)]
mymatrix = [[0 for i in range(4)] for i in range(4)]
for i in range(n):
[a,b] = input().split()
if(a=='A'):
mymatrix[0][(int(b)//3)%4]+=1
elif(a=='B'):
mymatrix[1][(int(b)//3)%4]+=1
elif(a=='C'):
mymatrix[2][(int(b)//3)%4]+=1
else:
mymatrix[3][(int(b)//3)%4]+=1
value = []
for a in range(4):
for b in range(4):
for c in range(4):
for d in range(4):
if(a!=b and a!=c and a!=d and b!=c and b!=d and c!=d):
mylist = [mymatrix[0][a],mymatrix[1][b],mymatrix[2][c],mymatrix[3][d]]
mylist.sort()
if(mylist[0]!=0):
value.append(mylist[0]*25 + mylist[1]*50 + mylist[2]*75 + mylist[3]*100)
elif(mylist[1]!=0):
value.append(mylist[3]*100 + mylist[1]*50 + mylist[2]*75 -100)
elif(mylist[2]!=0):
value.append(mylist[2]*75 + mylist[3]*100 -200)
elif(mylist[3]!=0):
value.append(mylist[3]*100 - 300)
else:
value.append(-400)

value = max(value)
myans += value
print(value)
print(myans)



62 changes: 62 additions & 0 deletions Codeforces_Contests/7_Round_674_Div_3/F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main() {
fast;
int n;
cin >> n;

string s;
cin >> s;

vector<vector<int>> dp(n + 1, vector<int>(3, 0));

int cur = 1;

for (int i = 1 ; i <= n ; i++) {
if (s[i - 1] == 'a' || s[i - 1] == '?') {
dp[i][0] = dp[i - 1][0] + cur;
dp[i][1] = dp[i - 1][1];
dp[i][2] = dp[i - 1][2];
}
if (s[i - 1] == 'b' || s[i - 1] == '?') {
dp[i][0] += dp[i - 1][0];
dp[i][1] += dp[i - 1][1] + dp[i - 1][0];
dp[i][2] += dp[i - 1][2];
}
if (s[i - 1] == 'c' || s[i - 1] == '?') {
dp[i][0] += dp[i - 1][0];
dp[i][1] += dp[i - 1][1];
dp[i][2] += dp[i - 1][2] + dp[i - 1][1];
}
if (s[i - 1] == '?') {
cur = (cur * 3) % MOD;
}
dp[i][0] %= MOD;
dp[i][1] %= MOD;
dp[i][2] %= MOD;
}
cout << dp[n][2] << "\n";
}
32 changes: 32 additions & 0 deletions Codeforces_Contests/9_Round_667_Div_3/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <string>
#include <vector>

#include <algorithm>
#include <cmath>

using namespace std;

int main()

{
int noOfTestCase{};
cin>>noOfTestCase;
long long a[noOfTestCase];
long long b[noOfTestCase];
for(int i=0;i<noOfTestCase;i++){
cin>>a[i];
cin>>b[i];
}
for(int i=0;i<noOfTestCase;i++){

if(abs(a[i]-b[i])==0){
cout<<"0"<<endl;
}else if(abs(a[i]-b[i])%10==0){
cout<<(abs(a[i]-b[i])/10)<<endl;
}else{
cout<<(abs(a[i]-b[i])/10)+1<<endl;
}
}

return 0;
}
59 changes: 59 additions & 0 deletions Codeforces_Contests/Educational Codeforces Round 96/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define MOD 1000000007
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
using namespace std;
typedef vector<int> vi;
typedef list<int> li;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename P> P dectobin(P a){if(a==0)return 0; else return(a%2 + 10*dectobin(a/2));}
template<typename Y> Y bintodec(Y a){int ans=0,b=1,t=a; while (t){int ld=t%10; t/=10;ans+=ld* b;b=b*2;} return ans; }
template<typename H> H modExp(H x, H n){ int r=1; while(n>0){if(n%2==1){r=(r*x)%MOD;}x=(x*x)%MOD;n/=2;}return r;}
template<typename T> T isPowerOfTwo(T x){return x && (!(x & (x - 1)));}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
//template<typename T> T extendedEuclid(T A,T B){if(B==0){d=A; x=1;y=0;}else{ extendedEuclid(B,A%B);int temp=x; x=y; y=temp-(A
//B)*y;}}
int32_t main(){
boost;osit;
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool ok=false;
if(n%3==0) cout<<n/3<<" "<<0<<" "<<0<<endl;
else if(n%5==0) cout<<0<<" "<<n/5<<" "<<0<<endl;
else if(n%7==0) cout<<0<<" "<<0<<" "<<n/7<<endl;
else{
for(int i=1;i<=n/3;i++){
for(int j=1;j<=(n-3*i)/5;j++){
int k=n-(3*i+5*j);
if(k%7==0){
cout<<i<<" "<<j<<" "<<k/7<<endl;
ok=true;
break;
}
}
if(ok) break;
}
if(ok==false) cout<<-1<<endl;
}
}
return 0;
}
46 changes: 46 additions & 0 deletions Codeforces_Contests/Educational Codeforces Round 96/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define MOD 1000000007
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
using namespace std;
typedef vector<int> vi;
typedef list<int> li;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename P> P dectobin(P a){if(a==0)return 0; else return(a%2 + 10*dectobin(a/2));}
template<typename Y> Y bintodec(Y a){int ans=0,b=1,t=a; while (t){int ld=t%10; t/=10;ans+=ld* b;b=b*2;} return ans; }
template<typename H> H modExp(H x, H n){ int r=1; while(n>0){if(n%2==1){r=(r*x)%MOD;}x=(x*x)%MOD;n/=2;}return r;}
template<typename T> T isPowerOfTwo(T x){return x && (!(x & (x - 1)));}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
//template<typename T> T extendedEuclid(T A,T B){if(B==0){d=A; x=1;y=0;}else{ extendedEuclid(B,A%B);int temp=x; x=y; y=temp-(A
//B)*y;}}
int32_t main(){
boost;osit;
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
int arr[n],sum=0;
rep(i,0,n) cin>>arr[i];
sort(arr,arr+n);
for(int i=n-1;i>=(n-k-1);i--) sum+=arr[i];
cout<<sum<<endl;
}
return 0;
}
Loading