Submission #92347

#TimeUsernameProblemLanguageResultExecution timeMemory
92347PajarajaGift (IZhO18_nicegift)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; long long gcd(long long a,long long b) { if(a==0) return b; return gcd(b%a,a); } int main() { long long n,k,cnt=0; long long t,sum=0,mi=1000000000000000000LL; scanf("%lld%lld",&n,&k); priority_queue<pair<long long,int> > pq,pq1; for(int i=0;i<n;i++) {scanf("%lld",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); mi=min(mi,t); sum+=t;} if(sum%k!=0) {printf("-1"); return 0;} while(pq.size()>=k && mi!=pq.top().first) { stack<pair<long long,int> > st; for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();} long long f=st.top().first; if(!pq.empty()) f-=pq.top().first; f=max(f,1); for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); mi=min(mi,st.top().first); st.pop();} cnt++; } if(pq.size()%n!=0) {printf("-1"); return 0;} if(!pq.empty() && pq.top().first%(k/gcd(n,k))!=0) {printf("-1"); return 0;} if(pq.empty()) printf("%lld\n",cnt); else printf("%lld\n",cnt+(n*mi)/(k*(mi/(k/gcd(n,k))))); while(cnt--) { stack<pair<long long,int> > st; for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();} long long f=st.top().first; if(!pq1.empty()) f-=pq1.top().first; f=max(f,1); 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"); } 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();} printf("%lld ",f); for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); printf("%d ",st.top().second); st.pop();} printf("\n"); } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:16:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k && mi!=pq.top().first)
        ~~~~~~~~~^~~
nicegift.cpp:22:12: error: no matching function for call to 'max(long long int&, int)'
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
nicegift.cpp:22:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
nicegift.cpp:22:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
nicegift.cpp:22:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
nicegift.cpp:22:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   f=max(f,1);
            ^
nicegift.cpp:36:12: error: no matching function for call to 'max(long long int&, int)'
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
nicegift.cpp:36:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
nicegift.cpp:36:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
nicegift.cpp:36:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   f=max(f,1);
            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from nicegift.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
nicegift.cpp:36:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   f=max(f,1);
            ^
nicegift.cpp:42:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:12: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:14: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",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); mi=min(mi,t); sum+=t;}
                        ~~~~~^~~~~~~~~~~