제출 #523468

#제출 시각아이디문제언어결과실행 시간메모리
523468RaresFelixGift (IZhO18_nicegift)C++17
100 / 100
893 ms89260 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <vector> #include <iostream> #include <queue> #define MN 1007171 using namespace std; using ll = long long; ll n, k, A[MN]; priority_queue<pair<ll, int> > S; vector<pair<ll, vector<int>>> O; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; ll sum = 0; for(ll i = 1; i <= n; ++i) cin >> A[i], S.push({A[i], i}), sum += A[i]; if(S.top().first > sum / k || sum % k) { cout << "-1\n"; return 0; } ll vmin, suma_ramasa, delta; vector<int> PU; while(!S.empty()) { suma_ramasa = sum; for(ll i = 1; i <= k; ++i) PU.push_back(S.top().second), suma_ramasa -= S.top().first, S.pop(); if(!S.empty()) delta = min(A[PU.back()], sum / k - S.top().first); else delta = A[PU.back()]; O.push_back(make_pair(delta, PU)); for(auto it : PU){ A[it] -= delta; sum -= delta; if(A[it]) S.push({A[it], it}); } PU.clear(); } cout << O.size() << "\n"; for(auto [c, v] : O) { cout << c << " "; for(auto it : v) cout << it << " "; cout << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

nicegift.cpp: In function 'int main()':
nicegift.cpp:26:8: warning: unused variable 'vmin' [-Wunused-variable]
   26 |     ll vmin, suma_ramasa, delta;
      |        ^~~~
#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...