WorstCoder45's blog

By WorstCoder45, history, 9 months ago, In English

Two new shops are opening inside a new building and k kinds of items are needed to stock shelves at each store. Given the prices of n items in two shops, choose exactly k indices in such a way that the minimum sum of arrays firstShop and secondShop over these indices is maximum.

Specifically, choose exactly k indices (i[1], i[2],...., i[k]) such that the value min(a[i[1]]+a[i[2]]+.... + a[i[k]], b1+b[i[2]]+...+b[i[k]]) is maximized. Find this maximum value.

Example:-

n=5, k=3

firstShop=[6, 3, 6, 5, 1]

secondShop = [1, 4, 5, 9, 2]

Choose the subset of indices as (0, 2, 3).

The value is min(6+6+5, 1+5+9)= 15, which is the maximum possible. Return 15 as the answer

1<=N,array-values<=50

My DP Solution :- O(N*K*|sum1|*|sum2|) ; where sum1 = total sum of first array ; sum2 = total sum of second array but it TLE's how to optimize?

dp[i][k][sum1][sum2] = returns true if it is possible to select k indices from (0....i) such that array1 has sum1 and array2 has sum2.

Full text and comments »

Tags dp
  • Vote: I like it
  • +3
  • Vote: I do not like it

By WorstCoder45, history, 4 years ago, In English

Link to the problem : https://www.codechef.com/AGPR2020/problems/ALPR2005

Statement :

Given a binary sequence of length $$$n$$$, find the minimum number of changes needed so that bitwise-xor of every subarray of size $$$k$$$ is exactly 1 .

1<=n,k<=100000 .

A change operation is defined as : "You can change "1" to "0" , vice-versa"

Similar problem : https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/

The only thing I could decipher till now is that the answer mainly depends on the first subarrays of size k .

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By WorstCoder45, history, 4 years ago, In English

This problem is from some old contest of codeforces , I don't remember its name anymore . But the problem idea seems interesting.

Problem :

Given $$$n$$$ segments $$$[l,r]$$$ , segment $$$[l1,r1]$$$ belongs to the first person, $$$[l2,r2]$$$ belongs to the second person, and so on...

Each person should select any one day/number from his own segment.

We have to find any assignment for every person to a particular day, such that every person has selected a unique day .

Example :

Range of first person : $$$[1,5]$$$

Range of second person : $$$[7,8]$$$

Solution : First person selects day-1 and second person selects day 7.

Another example :

Range of first person : $$$[1,2]$$$

Range of second person : $$$[1,3]$$$

Solution : First person selects day-1 and second person selects day 2.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it