# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1040513 | 2024-08-01T06:44:26 Z | 김은성(#10995) | Tricks of the Trade (CEOI23_trade) | C++17 | 8000 ms | 23124 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=1; i<=n; i++){ crit.push_back(make_pair(1, i)); crit.push_back(make_pair(i, n)); } 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2392 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2392 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Execution timed out | 8077 ms | 23124 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Execution timed out | 8077 ms | 23124 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2392 KB | Output is correct |
4 | Correct | 1 ms | 2392 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |