drunk_philosopher's blog

By drunk_philosopher, history, 5 years ago, In English

Hello. I am trying to attempt the following problem

https://www.spoj.com/problems/HELPR2D2/

After trying for a while, I figured the lowest index of each ship with capacity more than C can be picked by just binary searching all the ships(lower_bound) and subtract the respective volume. However, after a few WA attempts, I googled if I can find a solution.

There is no explanation though, but I can see only segtree implementation and I can't get my head around why its a segtree problem(or rather, why not just bsearch). Can anybody help me point out the flaw in binary search approach. It looks so obvious to me that it is binary search(but it isn't). Thanks in advance for any help. Here's my bsearch WA attempt:

int main()
{
  int t;
  cin >> t;

  while(t--)
  {
    vector<ll> a;
    int k, n;
    cin >> k >> n;
    set<ll> s;

    a.assign(100005, k);
    char c;
    int r, v;
    ll used = 0, usedvol = 0;
    char lead[16];
    
    forn(i, n)
    {
      scanf("%s", lead);
      if(lead[0] != 'b')
      {
        r = 1;
        v = atoi(lead);
      }
      else
      {
        cin >> r >> v;
        n-=r-1;
      }

        forn(i, r)
        {
          int lowidx = std::lower_bound(a.begin(), a.end(), v) - a.begin();
          a[lowidx]-=v;
          if(s.find(lowidx) == s.end())
          {
            used++;
            usedvol += v;
            s.insert(lowidx);
          }
          else
          {
            usedvol += v;
          }
        }
      }
     cout << used << " " << used * k - usedvol << endl;
    }
}

Full text and comments »

By drunk_philosopher, history, 5 years ago, In English

Hello, I am trying to understand the editorial of the following problem

https://www.codechef.com/problems/SETELE

Link to Editorial

https://discuss.codechef.com/t/setele-editorial/13549

I understand the editorial completely except for the reduced formula to calculate the expected value.

It's Cmst — (sum of maximum cost edge across all paths)/T where T is n(n+1)/2.

I don't understand how the editorialist arrived at this. Can anybody provide an intuition behind this? Thanks in advance!

Full text and comments »

By drunk_philosopher, history, 5 years ago, In English

When I click on the tutorial(en) of a problem statement, it redirects to the codeforces home page. Also all the Editorial links from the round announcements redirect to the home page. Am I the only one?

Full text and comments »