답안 #95322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95322 2019-01-30T05:27:38 Z Retro3014 만두 (JOI14_ho_t2) C++17
100 / 100
15 ms 632 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define INF 1000000000
#define MAX_M 10005

int N, M;
vector<int> P;
vector<pair<int, int> > B;
int DP[MAX_M+1];


int main(){
	scanf("%d%d", &M, &N);
	for(int i=0; i<M; i++){
		int x;
		scanf("%d", &x); P.push_back(x);
	}sort(P.begin(), P.end());
	for(int i=0; i<N; i++){
		int x, y;
		scanf("%d%d", &x, &y); B.push_back(make_pair(x, y));
	}
	for(int i=1; i<=M; i++) DP[i] = INF;
	for(int i=0; i<B.size(); i++){
		for(int j=M-B[i].first; j>=0; j--){
			DP[j+B[i].first] = min(DP[j+B[i].first], DP[j]+B[i].second);
		}
		if(B[i].first>M){
			DP[M] = min(DP[M], B[i].second);
		}
		int T = INF;
		for(int j=M; j>=0; j--){
			T = min(T, DP[j]); DP[j] = T;
		}
	}
	int ans = 0;
	int sum = 0;
	for(int i=1; i<=M; i++){
		sum+=P.back(); P.pop_back();
		ans = max(ans, sum-DP[i]);
	}
	printf("%d", ans);
	return 0;
}

Compilation message

2014_ho_t2.cpp: In function 'int main()':
2014_ho_t2.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<B.size(); i++){
               ~^~~~~~~~~
2014_ho_t2.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &M, &N);
  ~~~~~^~~~~~~~~~~~~~~~
2014_ho_t2.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x); P.push_back(x);
   ~~~~~^~~~~~~~~~
2014_ho_t2.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y); B.push_back(make_pair(x, y));
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 360 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 504 KB Output is correct
2 Correct 13 ms 632 KB Output is correct
3 Correct 15 ms 504 KB Output is correct
4 Correct 13 ms 380 KB Output is correct
5 Correct 14 ms 504 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 11 ms 376 KB Output is correct
8 Correct 13 ms 376 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 12 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 360 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 15 ms 504 KB Output is correct
12 Correct 13 ms 632 KB Output is correct
13 Correct 15 ms 504 KB Output is correct
14 Correct 13 ms 380 KB Output is correct
15 Correct 14 ms 504 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 11 ms 376 KB Output is correct
18 Correct 13 ms 376 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 12 ms 504 KB Output is correct
21 Correct 7 ms 504 KB Output is correct
22 Correct 10 ms 504 KB Output is correct
23 Correct 10 ms 508 KB Output is correct
24 Correct 10 ms 508 KB Output is correct
25 Correct 10 ms 632 KB Output is correct
26 Correct 10 ms 504 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 13 ms 632 KB Output is correct
29 Correct 13 ms 504 KB Output is correct
30 Correct 13 ms 504 KB Output is correct