Submission #103348

# Submission time Handle Problem Language Result Execution time Memory
103348 2019-03-29T20:27:34 Z tincamatei Art Exhibition (JOI18_art) C++14
100 / 100
402 ms 20984 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 500000;

struct Paint {
	long long a, b;
}v[1+MAX_N];

bool cmp(Paint a, Paint b) {
	return a.a < b.a;
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n;
	long long best, rez, sp;

	fscanf(fin, "%d", &n);

	for(int i = 0; i < n; ++i)
		fscanf(fin, "%lld%lld", &v[i].a, &v[i].b);
	sort(v, v + n, cmp);
	
	sp = rez = 0LL;
	best = v[0].a;
	
	/*for(int i = 0; i < n; ++i) {
		sp = 0LL;
		for(int j = i; j < n; ++j) {
			sp += v[j].b;
			rez = max(rez, sp - v[j].a + v[i].a);
			//if(sp - v[j].a + v[i].a == rez)
				//printf("%d %d->%lld\n", i, j, sp - v[j].a + v[i].a);
		}
	}*/

	for(int i = 0; i < n; ++i) {
		sp = sp + v[i].b;
		best = max(best, -sp + v[i].b + v[i].a);
		rez = max(rez, sp - v[i].a + best);
	}

	fprintf(fout, "%lld", rez);

	fclose(fin);
	fclose(fout);
	return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:27:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d", &n);
  ~~~~~~^~~~~~~~~~~~~~~
art.cpp:30:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%lld%lld", &v[i].a, &v[i].b);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 5 ms 444 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 6 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 4 ms 384 KB Output is correct
51 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 5 ms 444 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 6 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 4 ms 384 KB Output is correct
51 Correct 6 ms 384 KB Output is correct
52 Correct 274 ms 8156 KB Output is correct
53 Correct 262 ms 20896 KB Output is correct
54 Correct 402 ms 20956 KB Output is correct
55 Correct 265 ms 20944 KB Output is correct
56 Correct 266 ms 20936 KB Output is correct
57 Correct 258 ms 20812 KB Output is correct
58 Correct 271 ms 20872 KB Output is correct
59 Correct 233 ms 20968 KB Output is correct
60 Correct 259 ms 20960 KB Output is correct
61 Correct 279 ms 20728 KB Output is correct
62 Correct 243 ms 20896 KB Output is correct
63 Correct 317 ms 20860 KB Output is correct
64 Correct 223 ms 20860 KB Output is correct
65 Correct 293 ms 20872 KB Output is correct
66 Correct 273 ms 20856 KB Output is correct
67 Correct 232 ms 20984 KB Output is correct
68 Correct 256 ms 20788 KB Output is correct