Submission #168942

#TimeUsernameProblemLanguageResultExecution timeMemory
168942abilGift (IZhO18_nicegift)C++14
100 / 100
810 ms149160 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() #define int long long using namespace std; const int N = (1e6 + 12); const int mod = (1e9 + 7); const int INF = (1e18 + 12); int a[N], b[N]; vector<pair<int,int > > vec[N]; vector<int > ans[N]; int res[N]; main() { int n, k, sum = 0, mx = 0; scanf("%lld%lld", &n, &k); for(int i = 1;i <= n; i++){ scanf("%lld", &a[i]); sum += a[i]; mx = max(mx, a[i]); } if(sum % k != 0 || mx > sum / k){ cout << -1; return 0; } int cur_sum = 0; int sz = 0; for(int i = 1;i <= n; i++){ cur_sum += a[i]; if(cur_sum >= sum / k){ int rem = cur_sum - sum / k; cur_sum = rem; vec[sz].pb({a[i] - rem, i}); sz++; if(rem > 0){ vec[sz].pb({rem, i}); } } else{ vec[sz].pb({a[i], i}); } } int szofans = 1; while(1){ int mn = INF; for(int i = 0;i < sz; i++){ mn = min(mn, vec[i][b[i]].fr); } res[szofans] = mn; bool f = false; for(int i = 0;i < sz; i++){ vec[i][b[i]].fr -= mn; ans[szofans].pb(vec[i][b[i]].sc); if(vec[i][b[i]].fr == 0){ b[i]++; if(b[i] == vec[i].size()){ f = true; } } } if(f){ break; } szofans++; } cout << szofans << endl; for(int i = 1;i <= szofans; i++){ printf("%lld ", res[i]); for(auto to : ans[i]){ printf("%lld ", to); } printf("\n"); } }

Compilation message (stderr)

nicegift.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:64:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(b[i] == vec[i].size()){
        ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:24: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:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
#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...