Submission #638245

# Submission time Handle Problem Language Result Execution time Memory
638245 2022-09-05T06:08:50 Z colazcy Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 340 KB
#include <cstdio>
#include <cassert>
#include <algorithm>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_lIM = lim,REPN = 1;REPN <= REPN_lIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 1e5 + 100;

struct Node{
    int id,now,cap;
}val[maxn];
ll sum;
int n,ans[maxn];
int main(){
#ifndef ONLINE_JUDGE
    // std::freopen("fufu.in","r",stdin);
#endif
    std::scanf("%d",&n);
    rep(i,1,n){
        val[i].id = i;
        std::scanf("%d %d",&val[i].now,&val[i].cap);
        sum += val[i].now;
    }
    std::sort(val + 1,val + 1 + n,[](const Node a,const Node b){return a.cap > b.cap;});
    int cnt = n;
    rep(i,1,n){
        ans[val[i].id] = std::min(sum,(ll)val[i].cap);
        sum -= val[i].cap;
        cnt--;
        if(sum <= 0)break;
    }
    std::printf("%d\n",cnt);
    rep(i,1,n)std::printf("%d ",ans[i]);
    return 0;
}

Compilation message

psk.cpp: In function 'int main()':
psk.cpp:22:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     std::scanf("%d",&n);
      |     ~~~~~~~~~~^~~~~~~~~
psk.cpp:25:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         std::scanf("%d %d",&val[i].now,&val[i].cap);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct