Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. // Marcin Knapik
  2. #include<bits/stdc++.h>
  3. #pragma GCC optimize("O3")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  5. #pragma GCC optimize("Ofast")
  6. #pragma GCC optimize("unroll-loops")
  7. using namespace std;
  8.  
  9. // #include <ext/pb_ds/assoc_container.hpp> // order_of_key
  10. // #include <ext/pb_ds/tree_policy.hpp> // find by order
  11. // using namespace __gnu_pbds;
  12. // #define ordered_set tree< pair<int, int> , null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
  13.  
  14. // const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
  15. // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  16. // #define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
  17.  
  18. typedef long double ld;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21. typedef pair<ll, ll> pll;
  22. typedef pair<int, int> ii;
  23. typedef vector<int> vi;
  24. typedef vector<ii> vii;
  25. typedef vector<vi> vvi;
  26. typedef vector<vector<ii>> vvii;
  27. typedef vector< ll > vll;
  28. typedef vector< pll > vpll;
  29.  
  30. #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  31. #define sz(a) (int)(a).size()
  32. #define pb push_back
  33. #define all(c) (c).begin(), (c).end()
  34. #define rall(c) (c).rbegin(), (c).rend()
  35. #define REP(i, a, b) for (int i = (a); i <= (b); i++)
  36. #define FOR(i, a) for (int i = 0; i < (a); i++)
  37. #define TRAV(i, n) for(auto&i:n)
  38. #define beg(x) (*(x.begin()))
  39. #define re(x) int x; cin >>x;
  40. #define f first
  41. #define s second
  42.  
  43. template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
  44. template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
  45.  
  46. template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
  47. template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
  48. template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
  49. template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
  50. template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }
  51.  
  52. const ll INF = 1e9 + 7;
  53. const ll mod = 998244353;
  54. const ll BIG_INF = 1e18 + 7;
  55. const ll N = 1e6+7;
  56. const ll T = 1<<19;
  57.  
  58.  
  59. ll n, m, q;
  60.  
  61. int tab[N];
  62.  
  63. int main(){
  64. ios::sync_with_stdio(0);
  65. cin.tie(0);
  66.  
  67. cin >> n;
  68. vi ans;
  69. FOR(i, n){
  70. int temp;
  71. cin >> temp;
  72. ans = {temp};
  73. tab[temp]++;
  74. }
  75.  
  76. for(int i = 1; i < N; i++){
  77. if(tab[i] > 1){
  78. int suma = 0;
  79. int kon = i;
  80.  
  81. while(tab[kon] > 1){
  82. suma += tab[kon];
  83. kon++;
  84. }
  85.  
  86. kon--;
  87. vi temp = {};
  88. if(tab[i-1] > 0){
  89. temp.pb(i-1);
  90. }
  91. for(int j = i; j <= kon; j++){
  92. temp.pb(j);
  93. }
  94. if(tab[kon+1]){
  95. temp.pb(kon+1);
  96. }
  97. for(int j = kon; j >= i; j--){
  98. for(int k = 0; k < tab[j]-1; k++){
  99. temp.pb(j);
  100. }
  101. }
  102.  
  103. if(sz(temp) > sz(ans)){
  104. ans = temp;
  105. }
  106.  
  107. i = kon;
  108. }
  109. }
  110.  
  111. if(sz(ans) == 1){
  112. for(int i = 1; i < N-4; i++){
  113. if(tab[i] && tab[i+1]){
  114. cout << 2 << '\n';
  115. cout << i << ' ' << i+1 << '\n';
  116. exit(0);
  117. }
  118. }
  119. }
  120. cout << sz(ans) << '\n';
  121. cout << ans << '\n';
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement