답안 #1040459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040459 2024-08-01T04:46:09 Z 김은성(#10995) Tricks of the Trade (CEOI23_trade) C++17
10 / 100
8000 ms 5088 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]);
	for(i=1; i<=n; i++){
		for(j=i; j<=n; j++)
			ans = max(ans, profit(i, j, m));
	}
	for(i=1; i<=n; i++){
		for(j=i; j<=n; j++){
			if(profit(i, j, m) == ans)
				profit_ch(i, j, m);
		}
	}
	printf("%lld\n", ans);
	for(i=1; i<=n; i++){
		printf("%d", ch[i]);
	}
	return 0;
}

Compilation message

trade.cpp: In function 'll profit_ch(int, int, int)':
trade.cpp:44:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(i=0; i<p.size(); i++){
      |           ~^~~~~~~~~
trade.cpp: In function 'int main()':
trade.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
trade.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%lld", &c[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
trade.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%lld", &s[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 31 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 38 ms 2480 KB Output is correct
7 Correct 36 ms 2392 KB Output is correct
8 Correct 17 ms 2396 KB Output is correct
9 Correct 17 ms 2396 KB Output is correct
10 Correct 51 ms 2392 KB Output is correct
11 Correct 18 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 31 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 38 ms 2480 KB Output is correct
7 Correct 36 ms 2392 KB Output is correct
8 Correct 17 ms 2396 KB Output is correct
9 Correct 17 ms 2396 KB Output is correct
10 Correct 51 ms 2392 KB Output is correct
11 Correct 18 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 31 ms 2488 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 38 ms 2396 KB Output is correct
18 Correct 35 ms 2396 KB Output is correct
19 Correct 17 ms 2392 KB Output is correct
20 Correct 17 ms 2396 KB Output is correct
21 Correct 52 ms 2396 KB Output is correct
22 Correct 16 ms 2396 KB Output is correct
23 Correct 119 ms 2644 KB Output is correct
24 Execution timed out 8067 ms 2396 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Execution timed out 8015 ms 5088 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Execution timed out 8015 ms 5088 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 31 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 38 ms 2480 KB Output is correct
9 Correct 36 ms 2392 KB Output is correct
10 Correct 17 ms 2396 KB Output is correct
11 Correct 17 ms 2396 KB Output is correct
12 Correct 51 ms 2392 KB Output is correct
13 Correct 18 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 31 ms 2488 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 38 ms 2396 KB Output is correct
20 Correct 35 ms 2396 KB Output is correct
21 Correct 17 ms 2392 KB Output is correct
22 Correct 17 ms 2396 KB Output is correct
23 Correct 52 ms 2396 KB Output is correct
24 Correct 16 ms 2396 KB Output is correct
25 Correct 119 ms 2644 KB Output is correct
26 Execution timed out 8067 ms 2396 KB Time limit exceeded
27 Halted 0 ms 0 KB -