#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pii pair<int,pi>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) (int) a.size()
#define endl '\n'
#define data "data"
using namespace std;
const ll linf = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7, N = 1e4;
void add(int &a, int b)
{
a += b;
if(a>=MOD)
a-=MOD;
if(a<0)
a += MOD;
}
int modulo(int x)
{
if(x<=1)
return 1;
return (MOD - MOD/x) * modulo(MOD/x) % MOD;
}
int mul(int a, int b)
{
return (1ll *a%MOD * b%MOD) % MOD;
}
int n, m;
int p[N+3];
pi box[503];
ll dp[2][N+3];
ll pref[N+3];
void inp(void)
{
cin >> n >> m;
FOR(i, 1, n) cin >> p[i];
FOR(i, 1, m) cin >> box[i].fi >> box[i].se;
}
void solve(void)
{
sort(p+1, p+n+1, greater<int>());
memset(dp, -0x3f, sizeof(dp));
dp[0][0] = 0;
FOR(i, 1, n) pref[i] = pref[i-1] + 1ll * p[i];
FOR(i, 1, m)
{
int cur = i & 1;
int pre = !cur;
FOR(j, 0, n) dp[cur][j] = dp[pre][j];
FOR(j, 0, n)
{
int k = j - box[i].fi;
k = max(0, k);
if(dp[pre][k] < -linf) continue;
ll cost = pref[j] - pref[k] - box[i].se;
dp[cur][j] = max(dp[cur][j], dp[pre][k] + cost);
}
}
ll ans = 0;
FOR(i, 1, n) ans = max(ans, dp[m & 1][i]);
cout << ans;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(data".inp", "r"))
{
freopen(data".inp","r",stdin);
freopen(data".out","w",stdout);
}
inp();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
2014_ho_t2.cpp: In function 'int main()':
2014_ho_t2.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | freopen(data".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
2014_ho_t2.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | freopen(data".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |