This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah! So the idea is straight forward: 1. sort the input array and calculate partial_sum()2. find the negative\positive boundary with the accumulated give…
Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers from List A got left out. Can you find out the…
Sorting is often useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses also. Challenge Given a list of unsorted numbers, can you find the numbers that have the smallest absol…
C. Wizards and Numbers 题目连接: http://codeforces.com/problemset/problem/167/C Description In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it - a and b. The order of the numbers is not important. L…
A. Colourful Graph 可以在$2n$步之内实现交换任意两个点的颜色,然后就可以构造出方案. #include <bits/stdc++.h> using namespace std ; typedef long long LL; const int mod=1e9+7,Maxn=222; const LL Inf=1LL<<60; int n,m,K; int col[Maxn],col2[Maxn]; int done[Maxn],pre[Maxn]; vecto…
Maximum Remaining 题意:给n个数,取出两个数$a_{i}$,$a_{j}$,求$a_{i}\% a_{j}$取模的最大值 直接排个序,第二大(严格的第二大)模第一大就是答案了. #include <bits/stdc++.h> using namespace std; int a[(int)1e6]; int main() { ios::sync_with_stdio(false); cin.tie(); int n; cin >> n; ; i < n;…
Subtree Removal 很显然不可能选择砍掉一对有祖先关系的子树.令$f_i$表示$i$子树的答案,如果$i$不被砍,那就是$a_i + \sum\limits_j f_j$:如果$i$被砍,那就是$-x$.取个$max$就好了. 时间.空间复杂度$O(n)$. #include <bits/stdc++.h> using namespace std; ; int tc, n, xx; int a[N]; vector<int> g[N]; long long f[N];…
MASTERING CREATIVITY, 1st EditionThis guide is free and you are welcome to share it withothers.From James Clear:For most of my life, I didn't consider myself to be particularly creative. I didn't play a musicalinstrument (or even know how to read mus…