diff --git a/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob1.py b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob1.py new file mode 100644 index 0000000..dc8b16f --- /dev/null +++ b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob1.py @@ -0,0 +1,15 @@ +for __ in range(int(input())): + n = int(raw_input()) + # map(int, raw_input().split()) + a = [0,0,0] + b = [100,100,100] + for i in range(n): + [c,l,x] = map(int, raw_input().split()) + if x>a[l-1]: + a[l-1]=x + b[l-1]=c + elif x==a[l-1]: + if b[l-1]>c: + b[l-1]=c + for i in xrange(3): + print str(a[i])+' '+str(b[i]) diff --git a/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob2.py b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob2.py new file mode 100644 index 0000000..ebc126b --- /dev/null +++ b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob2.py @@ -0,0 +1,31 @@ +for kohli in range(input()): + n = int(input()) + x=[] + y=[] + xx=[] + yy=[] + ans=[] + for i in range(n): + a,b = map(int,raw_input().split(' ')) + x.append(a) + y.append(b) + # print(x,y) + for i in range(n): + yy.append([y[i],i]) + # print(yy) + yy.sort(key = lambda x:x[0]) + # print(yy) + yy = yy[::-1] + # print(yy) + for i in yy: + if(len(ans)==3): + break + if(x[i[1]] in xx): + continue + else: + xx.append(x[i[1]]) + ans.append(i[0]) + if(len(ans)==3): + print(sum(ans)) + else: + print('0') diff --git a/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob3.py b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob3.py new file mode 100644 index 0000000..4a450f0 --- /dev/null +++ b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob3.py @@ -0,0 +1,16 @@ +# cook your code here +t=int(raw_input()) +for a0 in xrange(t): + a,k=map(float,raw_input().split()) + b=map(float,raw_input().split()) + # print a,k,b + m=min(b) + if m<0: + for i in xrange(3): + b[i]+=abs(m) + [x1,x2,x3]=sorted(b) + if (k >= (x3-x1)/2): + print float(a*a) + else: + if x3-x1-2*k>a: print float(0) + else: print abs(x3-x1-2*k-a)*a diff --git a/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob4.cpp b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob4.cpp new file mode 100644 index 0000000..fb176bf --- /dev/null +++ b/CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob4.cpp @@ -0,0 +1,89 @@ +#include +#define F first +#define S second +using namespace std; + +typedef long long ll; +typedef pair pii; + +ll y[4][2010], sz[4]; + +ll case1(int l, int r) { + ll ans = 0; + int i, j; + for(i = 1; i <= sz[l]; ++i) { + ll cur = 0, cnt = 0; + for(j = 1; j <= sz[r]; ++j) { + ll z = abs(r - l)*abs(y[r][j] - y[l][i]) + 2*abs(r - l)*min(y[r][j], y[l][i]); + ans += cnt*z - cur; + cur += z; + cnt += 1; + } + } + return ans; +} + +int main() { + int t, i, j; + // freopen("in.txt", "r", stdin); + scanf("%d", &t); + while(t--) { + int n, u, v; + scanf("%d", &n); + sz[1] = sz[2] = sz[3] = 0; + for(i = 1; i <= n; ++i) { + scanf("%d %d", &u, &v); + sz[u]++; + y[u][sz[u]] = v; + } + for(i = 1; i <= 3; ++i) { + sort(y[i] + 1, y[i] + sz[i] + 1); + } + ll ans = 0; + //Case 1 and 2 + ans += case1(1, 2); + //Case 2 and 1 + ans += case1(2, 1); + // Case 2 and 3 + ans += case1(2, 3); + // Case 3 and 2 + ans += case1(3, 2); + // Case 1 and 3 + ans += case1(1, 3); + // Case 3 and 1 + ans += case1(3, 1); + // cout << ans << endl; + // Case 1, 2 and 3 + for(i = 1; i <= sz[1]; ++i) { + ll cur = 0, cnt = 0, ptr = 1; + for(j = 1; j <= sz[2]; ++j) { + ll z = abs(y[2][j] - y[1][i]) + 2*min(y[2][j], y[1][i]); + while(ptr <= sz[3] and y[3][ptr] < y[2][j] + y[2][j] - y[1][i]) ptr++; + ans += (ptr - 1)*z - (sz[3] - ptr + 1)*z; + // cout << "in " << ptr << endl; + } + } + // cout << ans << endl; + for(i = 1; i <= sz[3]; ++i) { + ll cur = 0, cnt = 0, ptr = 1; + for(j = 1; j <= sz[2]; ++j) { + ll z = abs(y[2][j] - y[3][i]) + 2*min(y[2][j], y[3][i]); + while(ptr <= sz[1] and y[1][ptr] < y[2][j] + y[2][j] - y[3][i]) ptr++; + ans += (ptr - 1)*z - (sz[1] - ptr + 1)*z; + } + } + // cout << ans << endl; + for(i = 1; i <= sz[1]; ++i) { + ll cur = 0, cnt = 0, ptr = 1; + for(j = 1; j <= sz[3]; ++j) { + ll z = 2*abs(y[3][j] - y[1][i]) + 2*2*min(y[3][j], y[1][i]); + while(ptr <= sz[2] and y[2][ptr] + y[2][ptr] <= y[1][i] + y[3][j]) ptr++; + ans += (ptr - 1)*z - (sz[2] - ptr + 1)*z; + } + } + // cout << ans << endl; + long double fin = (long double)ans/2.0; + printf("%.3Lf\n", fin); + } + return 0; +} diff --git a/CP/January Lunchtime 2018/prob1.py b/CP/January Lunchtime 2018/prob1.py index e69de29..b60a552 100644 --- a/CP/January Lunchtime 2018/prob1.py +++ b/CP/January Lunchtime 2018/prob1.py @@ -0,0 +1,58 @@ +for kohli in range(input()): + n = int(input()) + a = list(map(int, raw_input().split())) + c1=0 + c2=0 + sum=0 + for x in range(10): + i=0 + j=0 + for i in range(len(a)): + for j in range(len(a)): + if(j>len(a)): + break + if(len(a)==1): + break + if(len(a)==2): + sum = a[0]+a[1] + if(not(sum)&1): + # print(sum) + # print(a) + a.pop(0) + a.pop(0) + a.append(sum) + # print(a) + else: + if(i!=j and i=0 else j+len(a)-2) + # print(a) + else: + a.pop(j) + # print(a) + a.pop((i-1) if (i-1)>=0 else i+len(a)-2) + # print(a) + a.append(sum) + # print(a) + if(len(a)==1): + break + if(i>len(a)): + break + if(len(a)==1): + break + print(len(a)) + a[:] = [] + +''' +1 +5 +2 1 3 1 3 +''' diff --git a/CP/January Lunchtime 2018/prob2.py b/CP/January Lunchtime 2018/prob2.py new file mode 100644 index 0000000..e69de29 diff --git a/CP/JanuaryCookOff2018/prob5.cpp b/CP/JanuaryCookOff2018/prob5.cpp index e69de29..3ca5f77 100644 --- a/CP/JanuaryCookOff2018/prob5.cpp +++ b/CP/JanuaryCookOff2018/prob5.cpp @@ -0,0 +1 @@ +// Could not solve this motherf***er