Submission #849738

# Submission time Handle Problem Language Result Execution time Memory
849738 2023-09-15T08:52:25 Z efedmrlr Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 600 KB
#include <bits/stdc++.h>
#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)



using namespace std;

const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 1e5+5;
int n,m,q,k;
vector<int> t;
vector<array<int,2> > z;
vector<array<int,2> > res;
vector<int> ans;
void solve() {
    cin>>n;
    t.resize(n); z.resize(n);
    int sum = 0;
    for(int i = 0; i<n; i++) {
        cin>>t[i]>>z[i][0];
        z[i][1] = i;
        sum += t[i];
    }
    sort(z.begin(),z.end());
    int i;
    int last = 0;
    for(i = n-1; i>=0; i--) {
        sum-=z[i][0];
        
        if(sum <= 0) {
            last = z[i][0] + sum;
            res.pb({last, z[i][1]});
            break;
        }
        else {
            res.pb(z[i]);
        }
    }
    cout<<i<<"\n";
    ans.resize(n,0);
    for(int i = 0; i < res.size(); i++) {
        ans[res[i][1]] = res[i][0];
    }
    for(auto i : ans) {
        cout<<i<<" ";
    }


}
 
signed main() {
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}

Compilation message

psk.cpp: In function 'void solve()':
psk.cpp:45:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0; i < res.size(); i++) {
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct