Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals), problem: (F) Dirty Arkady’s Kitchen Solution in C/C++

By | 2017-07-24T18:14:00+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

import java.io.*; import java.util.*; import sun.security.pkcs11.Secmod.DbMode; public class F { static class Edge { int from, to; int idx; public Edge(int from, int to, int idx) { this.from = from; this.to = to; this.idx = idx; } } static class Event implements Comparable<Event> { [...]

Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals), problem: (E) Rusty String Solution in C/C++

By | 2017-07-24T18:12:27+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include<bits/stdc++.h> #define pi acos(-1) #define maxn 1148576 using namespace std; typedef long long ll; char s[maxn]; int n; int res[maxn]; struct node{double x,y;}a[maxn],b[maxn],w[2][maxn]; node operator +(node a,node b){return (node){a.x+b.x,a.y+b.y};} node operator -(node a,node b){return (node){a.x-b.x,a.y-b.y};} node operator *(node a,node b){return (node){a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};} void init(int k){ [...]

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals), problem: (F) Best Edge Weight Solution in C/C++

By | 2017-07-24T18:10:46+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <cstdlib> #include <cstdio> #include <map> #include <ctime> #include <vector> #define INF 2000000000 #define N 200010 using namespace std; bool in_MST[N]; int jump[N][18] , maxl[N][18] , fa[N]; int ans[N] , fir[N] , tot , rep[N] , [...]

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals), problem: (D) High Load Solution In C/C++

By | 2017-07-24T18:04:33+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include <cstdio> int main(){ int n, k; scanf("%d%d", &n, &k); int l = (n - 2) / k + 1; printf("%d\n", 2 * l - ((n - 1) % k == 1)); for(int i = 2; i <= n; i++) printf("%d %d\n", i, i [...]

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals), problem: (C) String Reconstruction Solution In C/C++

By | 2017-07-24T18:02:55+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include<bits/stdc++.h> using namespace std; const int maxn=2e6+5; int main() { char a[maxn]={}; int n,k,i; cin>>n; while(n--){ string x; cin>>x>>k; int t,len=x.size(),tt=-len; while(k--){ scanf("%d",&t); for(i=max(0,tt+len-t);i<len;i++) a[i+t]=x[i]; tt=t; } } for(i=maxn-1;!a[i];) i--; for(int j=1;j<=i;j++) putchar(a[j]?a[j]:'a'); return 0; }

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals), problem: (A) Restaurant Tables Solution in C/C++

By | 2017-07-24T18:00:07+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include <iostream> using namespace std; int main() { int n,a,b,bg=0,d=0,x; cin>>n>>a>>b; while(n--){ cin>>x; if(x==1) {if(a)a--; else if(b)b--,bg++; else if(bg)bg--; else d++; } else {if(b)b--;else d+=2; } } cout<<d; }

Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals), problem: (E) Perpetual Motion Machine Solution In C/C++

By | 2017-07-24T17:55:07+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include <bits/stdc++.h> using namespace std; #define inf 1023456789 #define linf 1023456789123456789ll #define pii pair<int,int> #define pipii pair<int, pii > #define pll pair<long long,long long> #define vint vector<int> #define vvint vector<vint > #define ll long long #define pdd pair<double, double> //#define DEBUG #ifdef DEBUG #define [...]

Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals), problem: (D) Singer House Solution In C/C++

By | 2017-07-24T17:52:36+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define LL long long using namespace std; const LL Maxn = 410; const LL Mod = 1e9+7; LL f[Maxn][Maxn], n; void add(LL &x, LL y) { x = (x+y)%Mod; } int main() { LL i, j, [...]

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (F) Bamboo Partition Solution In C/C++

By | 2017-07-24T17:50:48+00:00 July 24th, 2017|Categories: Uncategorized|Tags: , , , , , , , , , |

#include<cstdio> #include<algorithm> using namespace std; int n,a[110]; long long k,ans=0; int main(){ scanf("%d%lld",&n,&k); for (int i=1; i<=n; i++) scanf("%d",&a[i]); for (long long l=1,r; l<=1LL<<62; l=r+1){ // printf("%lld %lld\n",l,r); long long cnt=0,weight=0; r=1LL<<62; for (int i=1; i<=n; i++){ cnt+=(((a[i]-1)/l)+1)*l-a[i]; weight+=(a[i]-1)/l+1; if ((a[i]>l) && ((a[i]-1)/((a[i]-1)/l) < [...]

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (D) Office Keys Solution In C/C++

By | 2017-07-24T17:46:49+00:00 July 24th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , , |

#include<bits/stdc++.h> using namespace std; const int maxn=2e3+5; int main(){ int n,k,p,a[maxn],b[maxn]; int res=INT_MAX,i,j; cin>>n>>k>>p; for(i=0;i<n;i++) scanf("%d",a+i); for(i=0;i<k;i++) scanf("%d",b+i); sort(a,a+n); sort(b,b+k); for(i=0;i<=k-n;i++){ int t=0; for(j=0;j<n;j++) t=max(t,abs(a[j]-b[i+j])+abs(p-b[i+j])); res=min(t,res); } cout<<res; return 0; }