# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92340 | 2019-01-02T14:05:21 Z | Pajaraja | Gift (IZhO18_nicegift) | C++17 | 166 ms | 31840 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 252 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Incorrect | 0 ms | 256 KB | Jury has the answer but participant has not |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 252 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Incorrect | 0 ms | 256 KB | Jury has the answer but participant has not |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 252 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Incorrect | 0 ms | 256 KB | Jury has the answer but participant has not |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 166 ms | 31840 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | n=4 |
2 | Correct | 2 ms | 252 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Incorrect | 0 ms | 256 KB | Jury has the answer but participant has not |
5 | Halted | 0 ms | 0 KB | - |