Skip to content

Commit 9f9be25

Browse files
committed
March Challenge 2018
1 parent 3010074 commit 9f9be25

File tree

21 files changed

+1024
-143
lines changed

21 files changed

+1024
-143
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# International Coding League (Rated)
2+
3+
import math
4+
def readInts():
5+
return list(map(int, raw_input().strip().split()))
6+
def readInt():
7+
return int(raw_input())
8+
def readIntsindex0():
9+
return list(map(lambda x: int(x) - 1, input().split()))
10+
def readStrs():
11+
return raw_input().split()
12+
def readStr():
13+
return raw_input()
14+
def numlistTostr(list1):
15+
return ''.join(list1)
16+
def strlistTostr(list1):
17+
return ''.join(str(e) for e in list1)
18+
def strTolist(str):
19+
return str.split()
20+
def strlistTointlist(str):
21+
return map(int, str)
22+
def slicenum(number,x):
23+
return int(str(number)[:x])
24+
def numTobin(A):
25+
s = str(bin(A))[2:]
26+
s = '0'*(31-len(s)) + s
27+
return s
28+
def precise(num):
29+
return "{0:.10f}".format(num)
30+
def rsorted(a):
31+
return sorted(a,reverse=True)
32+
33+
for __ in range(readInt()):
34+
n,m = readInts()
35+
arr,a = [],[]
36+
for i in range(n):
37+
arr.append(readInts())
38+
for i in range(n):
39+
for j in range(m):
40+
a.append(arr[i][j])
41+
# print(arr)
42+
# print(a)
43+
a= rsorted(a)
44+
# print(a)
45+
sum1,sum2 =0,0
46+
for i in range(len(a)):
47+
if(i&1):
48+
sum2+=a[i]
49+
else:
50+
sum1+=a[i]
51+
if(sum2==sum1):
52+
print("Draw")
53+
# print(sum1,sum2)
54+
elif(sum2>sum1):
55+
print("Geno")
56+
# print(sum1,sum2)
57+
else:
58+
print("Cyborg")
59+
# print(sum1,sum2)
60+
61+
62+
63+
64+
'''
65+
3
66+
1 1
67+
3
68+
2 3
69+
4 4 4
70+
4 4 4
71+
2 3
72+
4 3 4
73+
4 4 4
74+
75+
Sample Output
76+
77+
Cyborg
78+
Draw
79+
Cyborg
80+
81+
Geno
82+
'''
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# International Coding League (Rated)
2+
from fractions import gcd
3+
import math
4+
def readInts():
5+
return list(map(int, raw_input().strip().split()))
6+
def readInt():
7+
return int(raw_input())
8+
def readIntsindex0():
9+
return list(map(lambda x: int(x) - 1, input().split()))
10+
def readStrs():
11+
return raw_input().split()
12+
def readStr():
13+
return raw_input()
14+
def numlistTostr(list1):
15+
return ''.join(list1)
16+
def strlistTostr(list1):
17+
return ''.join(str(e) for e in list1)
18+
def strTolist(str):
19+
return str.split()
20+
def strlistTointlist(str):
21+
return map(int, str)
22+
def slicenum(number,x):
23+
return int(str(number)[:x])
24+
def numTobin(A):
25+
s = str(bin(A))[2:]
26+
s = '0'*(31-len(s)) + s
27+
return s
28+
def precise(num):
29+
return "{0:.10f}".format(num)
30+
def rsorted(a):
31+
return sorted(a,reverse=True)
32+
33+
for __ in range(readInt()):
34+
n,k = readInts()
35+
string = readStr()
36+
con = 0
37+
col =n
38+
summ = 0
39+
for i in string:
40+
if(ord(i)-96>2*k):
41+
con+=1
42+
col-=1
43+
summ+=ord(i)-96
44+
# print(summ)
45+
lolo = k*(col-con)+summ
46+
p = gcd(abs(lolo),k)
47+
lolo/=p
48+
k/=p
49+
print lolo,k
50+
51+
'''
52+
Sample Input
53+
54+
2
55+
10 6
56+
abcdefghij
57+
10 1
58+
qwertyuiop
59+
60+
Sample Output
61+
62+
10 1
63+
159 1
64+
65+
66+
'''
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include<bits/stdc++.h>
2+
#define ll long long
3+
#define pb push_back
4+
#define endl '\n'
5+
#define pii pair<ll int,ll int>
6+
#define vi vector<ll int>
7+
#define all(a) (a).begin(),(a).end()
8+
#define F first
9+
#define S second
10+
#define sz(x) (ll int)x.size()
11+
#define hell 1000000007
12+
#define rep(i,a,b) for(ll int i=a;i<b;i++)
13+
#define lbnd lower_bound
14+
#define ubnd upper_bound
15+
#define bs binary_search
16+
#define mp make_pair
17+
const int inf =1e9;
18+
using namespace std;
19+
#define MAX 100005
20+
21+
int gcd(int a, int b) {
22+
while(b) {
23+
int r = a % b;
24+
a = b;
25+
b = r;
26+
}
27+
return a;
28+
}
29+
30+
int main() {
31+
ll t;
32+
cin>>t;
33+
while(t--)
34+
{
35+
ll n,m,a,b,c,d,p ;
36+
cin>>n>>m>>a>>b>>c>>d>>p;
37+
ll A,B,C;
38+
A = a+b;
39+
B = c+d;
40+
C = p+m*b+n*d;
41+
ll g = gcd(A,B);
42+
if(C %g!=0){
43+
cout<<"-1"<<endl;
44+
continue;
45+
}
46+
int ans = inf;
47+
int till = C / A;
48+
for(int N = m; N <= till; ++N) {
49+
int E = (C - N * A);
50+
if (E % B != 0) {
51+
continue;
52+
}
53+
E /= B;
54+
if (E < n) {
55+
break;
56+
}
57+
int S = N - m, W = E - n;
58+
ans = min(ans, N + S + E + W);
59+
}
60+
if (ans == inf) {
61+
ans = -1;
62+
}
63+
else {
64+
assert(ans >= n + m);
65+
}
66+
cout << ans << "\n";
67+
68+
69+
}
70+
71+
return 0;
72+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include<bits/stdc++.h>
2+
#define ll long long
3+
#define pb push_back
4+
#define endl '\n'
5+
#define pii pair<ll int,ll int>
6+
#define vi vector<ll int>
7+
#define all(a) (a).begin(),(a).end()
8+
#define F first
9+
#define S second
10+
#define sz(x) (ll int)x.size()
11+
#define hell 1000000007
12+
#define rep(i,a,b) for(ll int i=a;i<b;i++)
13+
#define lbnd lower_bound
14+
#define ubnd upper_bound
15+
#define bs binary_search
16+
#define mp make_pair
17+
using namespace std;
18+
#define N 100005
19+
20+
int main() {
21+
ll t;
22+
cin>>t;
23+
while(t--)
24+
{
25+
ll n,k;
26+
cin>>
27+
28+
}
29+
30+
return 0;
31+
}
32+
33+
/*
34+
35+
Sample Input
36+
37+
5 6
38+
1 3 4
39+
1 2 1
40+
1 1 4
41+
2 4 2 3
42+
2 4 2 1
43+
2 3 5 3
44+
45+
Sample Output
46+
47+
4
48+
1
49+
3
50+
-1
51+
4
52+
5
53+
54+
55+
*/

CP/ March Challenge 2018/p4.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,39 @@ def readStr():
99
return raw_input()
1010

1111

12-
for __ in range(readInt()):
13-
n,h = readInts()
14-
a = readInts()
15-
a = sorted(a)
16-
print(a)
17-
# summ = 0
18-
# for i in range(n):
19-
# summ+= a[i]
20-
diff = h-n
21-
if(n==h):
22-
print(a[n-1])
23-
continue
24-
for i in range(diff):
25-
print("yeh waala hai ", a[n+i-1])
26-
if(a[n+i-1]/2<=1):
27-
break
28-
j = a[n+i-1]/2
29-
a[n+i-1] -= j
30-
a.append(j)
31-
a = sorted(a)
32-
print(a)
33-
# di = i
34-
print(int(a[n+i]))
12+
for m in range(readInt()):
13+
strings = raw_input().split(" ")
14+
N= int(strings[0])
15+
H= int(strings[1])
16+
strings1=raw_input().split(" ")
17+
A= map(int, strings1)
18+
maxi = A[0]
19+
sumi = 0
20+
for i in range(len(A)):
21+
sumi += A[i]
22+
if(maxi < A[i]):
23+
maxi = A[i]
24+
flag=True
25+
#suitable values of K
26+
avg = sumi/H
27+
low = avg
28+
high = maxi
29+
#######################################3
30+
hr = 0
31+
while(low<=high):
32+
mid = (low+high)/2
33+
hr = 0
34+
for j in range(len(A)):
35+
if( A[j]%mid != 0):
36+
hr += A[j]/mid + 1
37+
else:
38+
hr += A[j]/mid
39+
if(hr <= H):
40+
ans = mid
41+
high = mid - 1
42+
else:
43+
low = mid + 1
44+
print ans
3545

3646

3747
'''

0 commit comments

Comments
 (0)