답안 #292980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292980 2020-09-07T15:18:34 Z Pajaraja Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 29868 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,t,cnt=0,sum=0,mx=-1;
	scanf("%d%d",&n,&k);
	priority_queue<pair<int,int> > pq,pq1;
	for(int i=0;i<n;i++) {scanf("%d",&t); mx=max(mx,t); sum+=t; pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1));}
	while(pq.size()>=k)
	{
		stack<pair<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
		for(int i=0;i<k;i++) {st.top().first--; if(st.top().first!=0) pq.push(st.top()); st.pop();}
		cnt++;
	}
	if((sum-mx)>=(k-1)*mx) {printf("-1"); return 0;}
	printf("%d\n",cnt);
	while(pq1.size()>=k)
	{
		printf("1 ");
		stack<pair<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
		for(int i=0;i<k;i++) {st.top().first--; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();}
		printf("\n");
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:9:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    9 |  while(pq.size()>=k)
      |        ~~~~~~~~~^~~
nicegift.cpp:18:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |  while(pq1.size()>=k)
      |        ~~~~~~~~~~^~~
nicegift.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
nicegift.cpp:8:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  for(int i=0;i<n;i++) {scanf("%d",&t); mx=max(mx,t); sum+=t; pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1));}
      |                        ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 29868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -