Mephistopheles_

Journey to the “The World’s Start”

Jul 26th, 2021 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #pragma GCC optimize ("Ofast,unroll-loops")
  2. #pragma GCC target ("avx2,fma")
  3. #include<bits/stdc++.h>
  4. //#include <ext/pb_ds/assoc_container.hpp>
  5.  
  6.  
  7. using namespace std;
  8. //typedef tree<ште,null_type,less<>, rb_tree_tag,
  9. //tree_order_statistics_node_update> indexed_set;
  10.  
  11. //rope
  12. #define forx(i,a,b) for (long long i = a; i < b; i++)
  13. #define INF 1e9
  14. #define all(x2) begin(x2),end(x2)
  15. #define size(t3) ((ll)(t3.size()))
  16. #define last(x) (*(x.end()-1))
  17. #define mod ll(1e9+7)
  18. using ll= long long;
  19. using ld= long double;
  20. using ull=unsigned long long;
  21. bool f(vector<ll>&tm,ll r,ll t){
  22.     vector<ll>dp(size(tm),0);
  23.     multiset<ll>s{0};
  24.     forx(i,1,size(dp)){
  25.         dp[i]=*s.begin()+tm[i];
  26.         s.insert(dp[i]);
  27.         if(size(s)>r)
  28.             s.erase(s.find(dp[i-r]));
  29.     }
  30.     if(last(dp)+size(tm)-1<=t)
  31.         return true;
  32.     else
  33.         return false;
  34. }
  35.  
  36. int main() {
  37.     ios::sync_with_stdio(false);
  38.     cin.tie(nullptr);
  39.     cout.tie(nullptr);
  40.     /*cout.setf(ios::fixed);
  41.     cout.precision(15);*/
  42.     /*freopen("input.txt", "r", stdin);
  43.     freopen("output.txt", "w", stdout);*/
  44.     ll n, t, x;
  45.     cin>>n>>t;
  46.     vector<ll> v;
  47.     forx(i, 0, n - 1) {
  48.         cin >> x;
  49.         v.push_back(x);
  50.     }
  51.     vector<ll> tm(n);
  52.     tm[0]=0;
  53.     tm[n-1]=0;
  54.     forx(i, 1, n-1 )cin >> tm[i];
  55.     ll left = 1;
  56.     ll right = n - 1;
  57.     while (left < right) {
  58.         ll mid = (left + right) / 2;
  59.         if (f(tm, mid, t))
  60.             right = mid;
  61.         else
  62.             left = mid + 1;
  63.     }
  64.     ll res=200000;
  65.     forx( i,0,size(v)){
  66.         if(i+1>=left && v[i]<res)
  67.             res=v[i];
  68.     }
  69.     cout << res;
  70. }
  71.  
Add Comment
Please, Sign In to add comment