Codeforces Round 890 | Problem C: To Make Max | Binary Search, Constructive Algorithms

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 15

  • @i_am_wiz
    @i_am_wiz ปีที่แล้ว +7

    Nice explanation. Try to post editorials from C onwards, they are really helpful

  • @kunalsutar3946
    @kunalsutar3946 ปีที่แล้ว

    You were the last person to look upto. If even your explaination wasn't helping I would have left the problem entirely. It took me nearly 2 hours to figure out the whole thing but thank god I sticked with it. Excellent explaination !

  • @shivamkushwaha1029
    @shivamkushwaha1029 10 หลายเดือนก่อน +1

    This was very helpful and your explanation made it easy to understand. Good Job buddy !

  • @harshtank7075
    @harshtank7075 4 หลายเดือนก่อน

    Legendary explanation

  • @vibhupandey9522
    @vibhupandey9522 8 หลายเดือนก่อน +1

    what an amazing question this was

  • @wizard-gg6et
    @wizard-gg6et ปีที่แล้ว

    I watched the tutorial on codeforces but it was hard for me and I watched many editorials on TH-cam but also they were hard but yours was good for me thanks a lot ❤

  • @kishorjha5028
    @kishorjha5028 ปีที่แล้ว

    thanks sir perfect explanation better than cf editorial

  • @pabitrakb5291
    @pabitrakb5291 3 หลายเดือนก่อน

    Niceee

  • @AbhinavVerma2602
    @AbhinavVerma2602 ปีที่แล้ว

    Please make Editorial of Problem E1 of the same Round.

  • @kamikazewarrior9800
    @kamikazewarrior9800 ปีที่แล้ว

    very nice explanation better than the editorial

  • @Mdenterprises8
    @Mdenterprises8 ปีที่แล้ว

    whats wrong in my code its cses dp question - projects recusrsive solution is giving right answer but as soon as im memoizing it its giving wrong answers
    #define ll long long
    #include
    using namespace std;
    ll solve(ll ind, ll prev, vector& nums, ll n, vector& dp) {
    if (ind == n) return 0;
    if (dp[ind][prev] != -1) return dp[ind][prev];

    ll notTake = solve(ind + 1, prev, nums, n, dp);
    ll take = INT_MIN;
    if (prev == -1 || nums[ind][0] > nums[prev][1]) {
    take = nums[ind][2] + solve(ind + 1, ind, nums, n, dp);
    }

    return dp[ind][prev] = max(notTake, take);
    }
    int main() {
    ll n;
    cin >> n;
    vector nums(n);
    for (int i = 0; i < n; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    nums[i].push_back(a);
    nums[i].push_back(b);
    nums[i].push_back(c);
    }
    vector dp(n, vector(n, -1));
    cout

  • @MahirJain-z3b
    @MahirJain-z3b ปีที่แล้ว

    I tried this using dp. but for some reason it doesnt work. Tho the recursive logic is correct. I am somehow not able to memoize it. Can someone please help :
    #include
    #include
    #include
    typedef long long ll;
    ll a[300009];
    using namespace std;
    int mod = 1e9 + 7;
    int solve(vector &arr, int i, int k, vector &dp) {
    if (i == 0 || k == 0) {
    int x = *max_element(arr.begin(), arr.end());
    if (k > 0 && arr[1] >= arr[0]) {
    return max(x, arr[0] + min(arr[1] - arr[0] + 1, k));
    }
    return x;
    }
    if (dp[i][k] != -1) {
    return dp[i][k];
    }
    int a = INT_MIN, b = INT_MIN;
    if (arr[i] > t;
    while (t--) {
    int n, k;
    cin >> n >> k;
    vector arr;
    for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    arr.emplace_back(a);
    }
    vector dp(n, vector(k + 1, -1));
    cout

    • @i_am_wiz
      @i_am_wiz ปีที่แล้ว +1

      You are incrementing arr[i] only once…the optimal number of increments might be greater than one
      So you need to run a loop from 0 till k applying all possible number of operations at the ith index.
      But that will result in K transitions per state which will result in TLE, the answer will be optimal though

    • @satyampatidar5848
      @satyampatidar5848 ปีที่แล้ว

      a[i]++
      // Function call
      Solve(a,b….)
      a[i]-
      this type of pattern only works if you going through all the possibilities (non dp)
      try to understand why and how

    • @MahirJain-z3b
      @MahirJain-z3b ปีที่แล้ว +2

      @@i_am_wizoh right, thanks got it