Advertisement
leminhkt

noname61(heodat)

Jun 22nd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;//                                        |\__/,|   (`\
  3. //                                                          _.|o o  |_   ) )
  4. /// ================================ Define Part ==========(((===(((=============
  5. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  6. #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
  7. #define pb     push_back
  8. #define ub     upper_bound
  9. #define ins    insert
  10. #define sz(x)  int(x.size())
  11. #define all(x) x.begin(), x.end()
  12.  
  13. typedef vector<int>     vi;
  14.  
  15. /// ================================ Independent  Functions ================================
  16. template<typename T>inline void writeUnsign(T n) {if (n > 9) writeUnsign(n/10);  putchar(n%10 + '0'); }
  17. template<typename T>inline void writeSigned(T x) {if (x < 0) putchar('-'), x = -x; writeUnsign(x); }
  18. 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;}
  19. inline int    readInt()    { int x;    return getSigned(x), x; }
  20.  
  21. /// ================================ Dependent  Functions ================================
  22. const int LOVE = 1411;
  23.  
  24. /// ================================ Main part ================================
  25.  
  26.  
  27. vi a = {0};
  28. int res, s, l;
  29. int d[1000001];
  30. set<int, greater<int>> temp;
  31.  
  32.  
  33. void binaryInsertionSort(int n){
  34.     FOR (i, max(1, l), n) {
  35.         int
  36.             key = a[i],
  37.             loc = ub(a.begin(), a.begin() + i, key) - a.begin();
  38.         ROF (j, loc, i) a[j + 1] = a[j];
  39.         a[loc] = key;
  40.     }
  41. }
  42.  
  43.  
  44. int main(){
  45.     for (int n = readInt(); n--;) {
  46.         for (s = readInt(); s--; temp.ins(readInt()));
  47.         while (!temp.empty())
  48.             res = max(res, d[*temp.begin()] = *temp.begin() + d[*(ub(all(a), *temp.begin()) - 1)]),
  49.             a.pb(*temp.begin()),
  50.             temp.erase(temp.begin());
  51.         s = sz(a);
  52.         binaryInsertionSort(s);
  53.         for (int i = 1; i < s; i++)
  54.             while(i < s && d[a[i]] <= d[a[i - 1]])
  55.                 s--,
  56.                 a.erase(a.begin() + i);
  57.         l = s;
  58.     }
  59.     writeSigned(res);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement