Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int N, S, M, ans = -1;
- int V[100];
- int dp[100][1000];
- void play(int idx, int vol) {
- if (idx < N) {
- if (vol + V[idx] <= M) {
- if (!dp[idx][vol + V[idx]]) {
- dp[idx][vol +V[idx]] = 1;
- play(idx + 1, vol + V[idx]);
- }
- }
- if (vol - V[idx] >= 0) {
- if (!dp[idx][vol - V[idx]]) {
- dp[idx][vol - V[idx]] = 1;
- play(idx + 1, vol - V[idx]);
- }
- }
- } else {
- if (vol > ans) ans = vol;
- }
- }
- int main() {
- scanf("%d %d %d", &N, &S, &M);
- for (int i = 0; i < N; i++) {
- scanf("%d", &V[i]);
- }
- play(0, S);
- printf("%d\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement