Submission #1263518

#TimeUsernameProblemLanguageResultExecution timeMemory
1263518tminh만두 팔기 (JOI14_manju)C++20
100 / 100
9 ms612 KiB
#include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 1e6 + 5; const ll oo = 1e18; bool START; int n, m; ll p[N] , dp[N]; ll get(int l, int r) { return p[r] - p[l - 1]; } inline void solve() { sort(p + 1, p + 1 + n, greater<ll>()); for (int i = 1; i <= n; ++i) { dp[i] = oo; p[i] += p[i - 1]; } dp[0] = 0; for (int i = 1; i <= m; ++i) { ll c, e; cin >> c >> e; for (int j = n; j >= 0; --j) { int nxt = min(j + c, 1ll * n); if (dp[j] != oo) dp[nxt] = min(dp[nxt], dp[j] + e); } } ll ans = 0; for (int i = 0; i <= n; ++i) ans = max(ans, p[i] - dp[i]); cout << ans; } inline void input() { cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> p[i]; return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

t2.cpp: In function 'int main()':
t2.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
t2.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...