Submission #638248

# Submission time Handle Problem Language Result Execution time Memory
638248 2022-09-05T06:13:17 Z Register Pod starim krovovima (COCI20_psk) C++14
50 / 50
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
int n,cnt,id[N],a[N],b[N],ans[N];
ll s;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]),s+=a[i],id[i]=i;
	sort(id+1,id+n+1,[&](int x,int y){return b[x]>b[y];});
	cnt=n;
	for(int i=1;i<=n&&s;i++) cnt--,s-=(ans[id[i]]=min(s,(ll)b[id[i]]));
	printf("%d\n",cnt);
	for(int i=1;i<=n;i++) printf("%d ",ans[i]);
	return 0;
}

Compilation message

psk.cpp: In function 'int main()':
psk.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
psk.cpp:9:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]),s+=a[i],id[i]=i;
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct