# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844701 | vjudge1 | Pod starim krovovima (COCI20_psk) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define li
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |