-
-
Save zekigurbuz/a962b2421216fb0a9ae2ec649d29ed22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma GCC optimize ("Ofast") | |
#pragma GCC target ("sse4") | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
template <class T> void ckmax(T& a, T b) { a = max(a, b); } | |
const int mxN = 2e5+5; | |
int N, M; | |
map<int, ll> v; | |
ll dp[mxN]; | |
int main() { | |
ios_base::sync_with_stdio(0); cin.tie(0); | |
cin >> N >> M; | |
for (int i = 0; i < N; ++i) { | |
string S; | |
ll V; | |
cin >> S >> V; | |
ckmax(v[int(S.size())], V); | |
} | |
ll ans = 0LL; | |
for (int i = 1; i <= M; ++i) { | |
for (pair<int, ll> c : v) { | |
if (i-c.first >= 0) { | |
ckmax(dp[i], dp[i-c.first] + c.second); | |
} | |
} | |
ckmax(dp[i], dp[i-1]); | |
ckmax(ans, dp[i]); | |
} | |
cout << ans << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment