Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;// |\__/,| (`\
- // _.|o o |_ ) )
- /// ================================ Define Part ==========(((===(((=============
- #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
- #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
- #define pb push_back
- #define ub upper_bound
- #define ins insert
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- typedef vector<int> vi;
- /// ================================ Independent Functions ================================
- template<typename T>inline void writeUnsign(T n) {if (n > 9) writeUnsign(n/10); putchar(n%10 + '0'); }
- template<typename T>inline void writeSigned(T x) {if (x < 0) putchar('-'), x = -x; writeUnsign(x); }
- template<typename T>inline void getSigned (T& n) {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign(c=='-');if(sign)c=getchar();n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';if(sign)n=-n;}
- inline int readInt() { int x; return getSigned(x), x; }
- /// ================================ Dependent Functions ================================
- const int LOVE = 1411;
- /// ================================ Main part ================================
- vi a = {0};
- int res, s, l;
- int d[1000001];
- set<int, greater<int>> temp;
- void binaryInsertionSort(int n){
- FOR (i, max(1, l), n) {
- int
- key = a[i],
- loc = ub(a.begin(), a.begin() + i, key) - a.begin();
- ROF (j, loc, i) a[j + 1] = a[j];
- a[loc] = key;
- }
- }
- int main(){
- for (int n = readInt(); n--;) {
- for (s = readInt(); s--; temp.ins(readInt()));
- while (!temp.empty())
- res = max(res, d[*temp.begin()] = *temp.begin() + d[*(ub(all(a), *temp.begin()) - 1)]),
- a.pb(*temp.begin()),
- temp.erase(temp.begin());
- s = sz(a);
- binaryInsertionSort(s);
- for (int i = 1; i < s; i++)
- while(i < s && d[a[i]] <= d[a[i - 1]])
- s--,
- a.erase(a.begin() + i);
- l = s;
- }
- writeSigned(res);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement