답안 #198397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198397 2020-01-25T21:50:58 Z ZwariowanyMarcin Pod starim krovovima (COCI20_psk) C++14
50 / 50
9 ms 380 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;		

const int nax = 1010;

int n;
int a[nax], b[nax], c[nax];

vector <int> vec;
int ind[nax];

int main() {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf ("%d%d", a + i, b + i);
		vec.pb(i);
		c[i] = a[i];
	}
	
	sort(vec.begin(), vec.end(), [](int x, int y) {
		return b[x] < b[y];
	});
	
	for (int i = 0; i < n; ++i) {
		ind[vec[i]] = i;
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int ja = vec[i];
		for (int j = 1; j <= n; ++j) 
			if (ind[ja] < ind[j]) {
				int ok = min(c[ja], b[j] - c[j]);
				c[j] += ok;
				c[ja] -= ok;
			}
		ans += (c[ja] == 0);
	}
	
	printf ("%d\n", ans);
	for (int i = 1; i <= n; ++i)
		printf ("%d ", c[i]);
	
			
	return 0;
}

Compilation message

psk.cpp: In function 'int main()':
psk.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &n);
  ~~~~~~^~~~~~~~~~
psk.cpp:27:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d%d", a + i, b + i);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 9 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct