답안 #137579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137579 2019-07-28T06:54:51 Z 송준혁(#3282) Coins (BOI06_coins) C++14
100 / 100
131 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, K;
vector<int> P;

int main(){
	scanf("%d %d", &N, &K);
	P.push_back(0);
	int x, y, t;
	scanf("%d %d", &x, &t);
	for (int i=2; i<=N; i++){
		scanf("%d", &y);
		if (!t){
			int k = upper_bound(P.begin(), P.end(), y-x-1) - P.begin() - 1;
			if (k+1 >= P.size()) P.push_back(x + P[k]);
		}
		x = y;
		scanf("%d", &t);
	}
	if (!t) P.push_back(x + *(--P.end()));
	int k = upper_bound(P.begin(), P.end(), K-1) - P.begin() - 1;
	if (k == 0) printf("0\n%d\n", K-1);
	else printf("%d\n%d\n", k, K-P[k]);
	return 0;
}

Compilation message

coins.cpp: In function 'int main()':
coins.cpp:18:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (k+1 >= P.size()) P.push_back(x + P[k]);
        ~~~~^~~~~~~~~~~
coins.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~
coins.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &x, &t);
  ~~~~~^~~~~~~~~~~~~~~~~
coins.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &y);
   ~~~~~^~~~~~~~~~
coins.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &t);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 119 ms 376 KB Output is correct
8 Correct 118 ms 380 KB Output is correct
9 Correct 131 ms 480 KB Output is correct
10 Correct 131 ms 504 KB Output is correct