Комментарии
На QAQAutoMatonIOI2022 China Team, 4 года назад
+8

NRolly will win IOI2022!

На SingingingingingBinary search but infinite loop, 4 года назад
+26

Well, what I do is...

int l = 0, r = n; // being l the number that definitely works, and r the one that definitely does not
while(l + 1 < r){
    int m = (l + r) / 2; 
    (ok(m)? l : r) = m;
}
cout << l << "\n"; // so, here l is the maximum value that holds some propriety

This works since when l + 1 < r, m != l and m != r, and when l + 1 = r , the loop should finish.

На albertolg101CIIC 2021's participants, 5 лет назад
+56

These are the ones going from Peru:

На salt_n_iceReason for the TLE?, 5 лет назад
+9

Now got it. Don't use "endl", use "\n" instead.

На salt_n_iceReason for the TLE?, 5 лет назад
0

It is RTE, try "resize" instead of "reserve".

I got accepted.

It is only dp[x][y][z] // x : cur_plate, y : fullness, z = happiness.

Firstly, I did simply that and got MLE.

My AC code below.

#include<bits/stdc++.h> 
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define ps() cout << "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;

using namespace std;
const int MOD = 1e9 + 7, MOD1 = (119 << 23) | 1;
const int INF = 1e9 + 5, MAX = 2e5 + 5; 
int main(){
   cpu();
   int n; cin >> n; 
   vector<int> l(n + 1), f(n + 1);
   for(int i = 0; i < n; i++){
      cin >> l[i] >> f[i];
   }  
   vector<vector<int>> dp(101, vector<int> (5001, -1000));
   dp[0][0] = 0
   int ans = 0;
   for(int i = 1; i <= n; i++){
      vector<vector<int>> cur = dp;
      for(int j = 0; j <= 100; j++){
         for(int k = 0; k <= 5000; k++){
            if(j >= l[i - 1] && k >= f[i - 1])
               dp[j][k] = max(dp[j][k], cur[j - l[i - 1]][k - f[i - 1]] + 1);
            if(k >= 100){
               ans = max(ans, dp[j][k]);
            }
         }
      }
   }
   cout << ans << "\n";
   return 0;
}

dp[x][y]: Number of particles that bounce in the x-th plane with y ages passed from the beginning. So, if (y & 1) then all those are bouncing to the left, and to the right otherwise. It is not difficult to notice that if(y & 1)

$$$dp[i][j] = dp[i-1][j-1] + dp[i-1][j-2] + ... dp[i-1][0]$$$

that leads to

$$$dp[i][j] = dp[i-1][j-1] + dp[i][j-1]$$$

the other case is analogous. Finally, I need to add dp[i][j] to ans for all i < n && j <= k, those are the cases when those particles don't bounce.

Obviously, 111382908 .

Another approach 101883649.