답안 #674924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674924 2022-12-26T15:34:22 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
 
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define ppb pop_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";
#define vc vector<char>
#define vvc vector<vc>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
#define int long long
#define ld long double
const int INF = 1e18;
const int inf = 1e9;
 
void solve(){
    int n; cin >> n;
    vi t(n), z(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> t[i] >> z[i];
        sum += t[i];
    }
    
    vi ans(n);
    vi ix(n);
    for(int i=0; i<n; i++) ix[i] = i;
    sort(all(ix), [&](int a, int b){
        return (z[a] > z[b]);
    });

    for(int i=0; i<n && sum; i++){
        int aux = min(z[ix[i]], sum);
        ans[ix[i]] += aux;
        sum -= aux;
    }
    cout << count(all(ans), 0LL) << "\n";
    print(ans);
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int tt = 1;
    // cin >> tt;
    while(tt--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct