답안 #500255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500255 2021-12-30T14:25:49 Z Mounir Pod starim krovovima (COCI20_psk) C++14
50 / 50
2 ms 204 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define pb push_back
#define pii pair<int, int>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define x first
#define y second
#define int long long
using namespace std;

signed main(){
      int nVals; cin >> nVals;
      int sum = 0;
      vector<pii> volumes;
      for (int iVal = 0; iVal < nVals; ++iVal){
            int cur, maxi; cin >> cur >> maxi;
            sum += cur;
            volumes.pb({maxi, iVal});
      }
      sort(all(volumes)); reverse(all(volumes));
      int i = 0; 
      vector<int> quantites(nVals, 0);
      while (i < nVals && sum > 0){
            quantites[volumes[i].second] = min(volumes[i].first, sum);
            sum -= volumes[i++].first;
      }
      cout << nVals - i << endl;
      for (int quantite : quantites)
            cout << quantite << " ";
      cout << endl;
      return 0;   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct