[BOJ] 퇴사
Date:
[BOJ] 퇴사
Problem URL : 퇴사
#include<iostream>
#include<vector>
#include<algorithm>
#define p pair<int,int>
using namespace std;
int n;
int ans;
vector<p> v;
void dfs(int idx, int cost) {
if (idx == v.size()) {
ans = ans < cost ? cost : ans;
return;
}
dfs(idx + 1, cost);
if (idx + v[idx].first <= v.size()) {
dfs(idx + v[idx].first, cost + v[idx].second);
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ans = -1;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
v.push_back({ a, b });
}
dfs(0, 0);
cout << ans << endl;
return 0;
}
댓글