# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040511 | 2024-08-01T06:42:59 Z | 김은성(#10995) | Tricks of the Trade (CEOI23_trade) | C++17 | 8000 ms | 15304 KB |
#include <cstdio> #include <algorithm> #include <vector> #include <cstring> #include <string> #include <set> #include <map> #include <deque> #include <queue> using namespace std; typedef long long ll; const ll INF = 0x3fffffffffffffff; ll c[250009], s[250009]; bool ch[250009]; ll profit(int l, int r, int k){ vector<ll> temp; if(r-l+1 < k) return -INF; int i; ll ans = 0; vector<ll> p; for(i=l; i<=r; i++){ ans -= c[i]; p.push_back(s[i]); } sort(p.begin(), p.end(), [](ll &u, ll &v){return u>v;}); for(i=0; i<k; i++) ans += p[i]; return ans; } ll profit_ch(int l, int r, int k){ vector<ll> temp; if(r-l+1 < k) return -INF; int i; ll ans = 0; vector<pair<ll, int> > p; for(i=l; i<=r; i++){ ans -= c[i]; p.push_back(make_pair(-s[i], i)); } sort(p.begin(), p.end()); for(i=0; i<p.size(); i++){ if(-p[i].first >= -p[k-1].first) ch[p[i].second] = 1; } return ans; } int main(){ int n, m, i, j; ll ans = -INF; scanf("%d %d", &n, &m); for(i=1; i<=n; i++) scanf("%lld", &c[i]); for(i=1; i<=n; i++) scanf("%lld", &s[i]); vector<pair<int, int> > crit; vector<int> st; for(i=1; i<=n; i++){ if(!st.empty() && s[st.back()] <= s[i]){ crit.push_back(make_pair(st.back(), i)); st.pop_back(); } if(!st.empty()) crit.push_back(make_pair(st.back(), i)); st.push_back(i); } for(i=1; i<=n-m+1; i++) crit.push_back(make_pair(i, i+m-1)); for(i=0; i<crit.size(); i++){ ans = max(ans, profit(crit[i].first, crit[i].second, m)); } for(i=0; i<crit.size(); i++){ if(profit(crit[i].first, crit[i].second, m) == ans) profit_ch(crit[i].first, crit[i].second, m); } printf("%lld\n", ans); for(i=1; i<=n; i++){ printf("%d", ch[i]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2392 KB | Output is correct |
2 | Correct | 99 ms | 15304 KB | Output is correct |
3 | Correct | 96 ms | 14780 KB | Output is correct |
4 | Execution timed out | 8042 ms | 14776 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2392 KB | Output is correct |
2 | Correct | 99 ms | 15304 KB | Output is correct |
3 | Correct | 96 ms | 14780 KB | Output is correct |
4 | Execution timed out | 8042 ms | 14776 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Correct | 0 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |