답안 #334942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334942 2020-12-10T12:08:52 Z ronnith Sličice (COCI19_slicice) C++14
90 / 90
70 ms 1388 KB
#include <bits/stdc++.h>
#define trav(a, b) for(auto a : b)
#define mk make_pair
#define f first
#define s second
#define vi vector<int>
#define pb push_back

using namespace std;

int main(){
	// ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	int p[n], b[m + 1];
	for(int i = 0;i < n;i ++)scanf("%d", &p[i]);
	for(int i = 0;i < m + 1;i ++)scanf("%d", &b[i]);
	int dp[n][k + 1];
	for(int i = 0;i < n;i ++){
		for(int j = 0;j <= k;j ++){
			dp[i][j] = 0;
			if(i == 0){
				int nw = min(j + p[i], m);
				dp[i][j] = b[nw];
			} else {
				for(int K = p[i];K - p[i] <= j and K <= m;K ++){
					dp[i][j] = max(dp[i][j], b[K] + dp[i - 1][j - (K - p[i])]);
				}
			}
		}
	}
	printf("%d\n", dp[n - 1][k]);
	return 0;
}

Compilation message

slicice.cpp: In function 'int main()':
slicice.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
slicice.cpp:16:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  for(int i = 0;i < n;i ++)scanf("%d", &p[i]);
      |                           ~~~~~^~~~~~~~~~~~~
slicice.cpp:17:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  for(int i = 0;i < m + 1;i ++)scanf("%d", &b[i]);
      |                               ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 69 ms 1388 KB Output is correct
4 Correct 68 ms 1260 KB Output is correct
5 Correct 68 ms 1388 KB Output is correct
6 Correct 67 ms 1260 KB Output is correct
7 Correct 68 ms 1260 KB Output is correct
8 Correct 70 ms 1260 KB Output is correct
9 Correct 66 ms 1260 KB Output is correct
10 Correct 70 ms 1388 KB Output is correct