Skip to content

Instantly share code, notes, and snippets.

@qjatn0120
Created March 23, 2023 16:35
Show Gist options
  • Save qjatn0120/e3dce378b933c9f4fbb01bbe8abac130 to your computer and use it in GitHub Desktop.
Save qjatn0120/e3dce378b933c9f4fbb01bbe8abac130 to your computer and use it in GitHub Desktop.
#ifdef DEBUG
#include "debug.h"
#endif // DEBUG
#ifndef DEBUG
template <typename T>
void debug(T &x){}
template <typename T>
void debug(T &x, int i, int j){}
#endif // DEBUG
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
int getResult(int c, int Min, int Max){
for(int i : v) c = min(Max, max(c - i, Min));
return c;
}
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
int n, a, b;
cin >> n >> a >> b;
vector <vector <int> > ans(a + 1, vector <int> (b + 1));
v.resize(n);
for(int i = 0; i < n; i++) cin >> v[i];
for(int sum = 0; sum <= a + b; sum++){
int lo = max(0, sum - b), hi = min(a, sum);
int Min = lo, Max = hi;
int minVal = getResult(Min, Min, Max);
while(lo < hi){
int mid = (lo + hi + 1) >> 1;
if(getResult(mid, Min, Max) == minVal) lo = mid;
else hi = mid - 1;
}
int maxVal = getResult(Max, Min, Max);
for(int c = Min; c <= Max; c++){
int d = sum - c;
if(c <= lo) ans[c][d] = minVal;
else ans[c][d] = min(maxVal, minVal + c - lo);
}
}
for(vector <int> &v : ans){
for(int val : v) cout << val << " ";
cout << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment