Since I am a newbie. I want to know how you guys practice solving problems. Do you guys practice by solving the problemset or by participating virtual contests? Any other advices are welcome.

By Shayan

Before stream
01:51:59

# | User | Rating |
---|---|---|

1 | tourist | 3690 |

2 | jiangly | 3647 |

3 | Benq | 3581 |

4 | orzdevinwang | 3570 |

5 | Geothermal | 3569 |

5 | cnnfls_csy | 3569 |

7 | Radewoosh | 3509 |

8 | ecnerwala | 3486 |

9 | jqdai0815 | 3474 |

10 | gyh20 | 3447 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 174 |

2 | awoo | 164 |

3 | adamant | 163 |

4 | TheScrasse | 159 |

5 | nor | 157 |

6 | maroonrk | 155 |

7 | -is-this-fft- | 152 |

8 | Petr | 146 |

8 | orz | 146 |

10 | BledDest | 145 |

I am struggling on solving the problem 1873E problem div4. I wrote the solution but few test cases are wrong and I can't find the flaw in my code. Plz Help!!!

```
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
int main() {
ll t;
cin >> t;
while (t--) {
ll n, x;
cin >> n >> x;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
ll left = 0, right = a[n - 1];
ll height = 0;
while (left <= right) {
ll mid = (left + right) / 2;
ll sum = 0;
for (int i = 0; i < n; i++) {
if (mid > a[i]) {
sum += mid - a[i];
}
}
if (sum <= x) {
height = mid;
left = mid + 1;
}
else {
right = mid - 1;
}
}
cout << height << '\n';
}
return 0;
}
```

void search(int k) {
if (k == n) {
// process subset
} else {
search(k+1);
subset.push_back(k);
search(k+1);
subset.pop_back();
}
}

I am having a really hard time understand this code. I especially don't understand how 'k' turns to 2 after 'k' reaches 3. I don't understand because there's no such code that does search(k-1) but it backtracks automatically. I think It's related to the thing backtracking. Someone plz help!!!

Should I practice CP by problems rating or by algorithm topics?

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/18/2024 17:08:01 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|