Comments

.

Understood it. Thanks for providing the explanation.

Thanks for providing a test case. Can you explain to me why my logic is wrong?

For problem D, can't we use the inclusion/exclusion principle to count duplicate occurrences?
Here is my solution, but it's giving WA in test 10.
These are the steps of my solution:
1. Compute all the intervals [i,j] such that the number of 1 in the interval is k. Let s1, s2, s3,...sk be the intervals.
2. Number of common combinations between s1, s2, s3,...si is the arrangement of one and zero that are present in the intersection of these. Then use inclusion and exclusion principle to get union of these.

On beginner_610 → Stuck in a problem., 5 years ago
0

You can check my code in the below comment. It is much simpler and intuitive.

On beginner_610 → Stuck in a problem., 5 years ago
0

Your code is not correct.

1
2 2 2 1
2 3

Answer should be 4, but this code outputs 5.

				if(j<y && pq.top().first>vec[j])
				{
					pq.push(make_pair(vec[j],j));
					++j;
					++i;
				}

Here is the mistake. If you selected 2, then instead of selecting 3 it will select 2.

On beginner_610 → Stuck in a problem., 5 years ago
0

This question can be solved greedily. - In a set(multiset to be specific), the printing finish time will be stored for each printing machine. Initially, all printing machines will be available so if we take any machine its ending time will be the time it takes to print a book. Suppose we take 1st machine with time 5, then if we take it next time its task will end at 10. So, we will replace the finishing time for 1st machine to be 10. - Similar logic is used for binding machine's job.

Here is my code.

#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

void solve() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	multiset<pair<ll,ll>> print;
	for(int i=0, t; i<y; i++) {
		cin >> t;
		print.insert({t, t});
	}
	multiset<ll> bound;
	for(int i=0; i<min(x, z); i++)
		bound.insert(0);
	ll ans, cur, t;
	for(int i=0; i<x; i++) {
		cur = print.begin()->first;
		t = print.begin()->second;
		print.erase(print.begin());
		print.insert({cur+t, t});
		ans = max(cur, *bound.begin())+k;
		bound.erase(bound.begin());
		bound.insert(ans);
	}
	cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int _t; cin >> _t; while(_t--)
    solve();
}

107905723 In line 150, you are initializing p with INT_MAX, it should be zero because if you don't consider any element ie prev sum, the value of p should be 0.

On ed1d1a8d → TLE on SUB_PROB (SPOJ), 6 years ago
0

I have tried to solve the problem using string hashing. But I got TLE. I have solved the problem with O(n*m) complexity. How I can optimize it? Here is my code -- https://ideone.com/zrInz2