Submission #92340

#TimeUsernameProblemLanguageResultExecution timeMemory
92340PajarajaGift (IZhO18_nicegift)C++17
0 / 100
166 ms31840 KiB
#include <bits/stdc++.h> #define MAXN 1000007 using namespace std; long long gcd(long long c,long long b) { if(c==0) return b; return gcd(b%c,c); } pair<long long,int> a[MAXN]; int main() { long long n,k,cnt=0; long long t,sum=0,s1=0; scanf("%lld%lld",&n,&k); priority_queue<pair<long long,int> > pq,pq1; for(int i=0;i<n;i++) {scanf("%lld",&a[i].first); sum+=a[i].first; a[i].second=i+1;} if(sum<=100000) { for(int i=0;i<n;i++) pq.push(a[i]); while(pq.size()>=k) { stack<pair<long long,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++; } for(int i=0;i<n-k;i++) s1+=a[i].first; if(sum%k!=0 || s1<a[n-1].first) {printf("-1"); return 0;} printf("%lld\n",cnt); for(int i=0;i<n;i++) pq1.push(a[i]); while(pq1.size()>=k) { stack<pair<long long,int> > st; printf("1 "); 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"); } } else { if(pq.top().first%(k/gcd(n,k))!=0) {printf("-1"); return 0;} long long f=pq.top().first/(k/gcd(n,k)); while(pq.size()>=k) { stack<pair<long long,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-=f; if(st.top().first!=0) pq.push(st.top()); st.pop();} cnt++; } printf("%lld\n",cnt); while(pq1.size()>=k) { stack<pair<long long,int> > st; for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();} printf("%lld ",f); for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();} printf("\n"); } } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:20:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq1.size()>=k)
        ~~~~~~~~~~^~~
nicegift.cpp:44:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq1.size()>=k)
        ~~~~~~~~~~^~~
nicegift.cpp:13:12: warning: unused variable 't' [-Wunused-variable]
  long long t,sum=0,s1=0;
            ^
nicegift.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~
nicegift.cpp:16:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) {scanf("%lld",&a[i].first); sum+=a[i].first; a[i].second=i+1;}
                        ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...