Submission #341923

# Submission time Handle Problem Language Result Execution time Memory
341923 2020-12-31T13:16:54 Z ignaciocanta Art Exhibition (JOI18_art) C++14
100 / 100
217 ms 24812 KB
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
 
using namespace std;
 
using tint = long long;
using ld = long double;
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
 
using pi = pair<tint,tint>;
using pl = pair<tint,tint>;
using vi = vector<int>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vl = vector<tint>;
using vb = vector<bool>;

#define pb push_back
#define pf push_front
#define rsz resize
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sz(x) (int)(x).size()
#define ins insert

#define f first
#define s second
#define mp make_pair
 
#define DBG(x) cerr << #x << " = " << x << endl;
 
const int MOD = 1e9+7;
const int mod = 998244353;
const int MX = 1005; 
const tint INF = 1e18; 
const int inf = 2e9;
const ld PI = acos(ld(-1)); 
const ld eps = 1e-8;
 
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
 
template<class T> void remDup(vector<T> &v){ 
    sort(all(v)); v.erase(unique(all(v)),end(v));
}
 
bool valid(int x, int y, int n, int m){
    return (0<=x && x<n && 0<=y && y<m);
}
 
int cdiv(int a, int b) { return a/b+((a^b)>0&&a%b); } //redondea p arriba
int fdiv(int a, int b) { return a/b-((a^b)<0&&a%b); } //redonde p abajo
 
void NACHO(string name = "lightson"){
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen((name+".in").c_str(), "r", stdin);
    //freopen((name+".out").c_str(), "w", stdout);
}

int main(){
	NACHO();
	// supongamos que mi minimo actual es min y mi maximo actual es max
	// obviamente, voy a querer meter a todos aquellos elementos con min <= a[i].f <= max
	// ya que no me afecta max-min y aumenta S.
	// es por esto que si los ordenamos por a[i].f siempre vamos a querer tomar rangos
	// consecutivos. Esto ultimo lo resolvemos con suma de prefijos
	int n; cin >> n;
	vpi a (n);
	F0R(i, n) cin >>a[i].f >> a[i].s;
	sort(all(a));
	vl s (n+1, 0);
	FOR(i, 1, n+1) s[i] = s[i-1]+a[i-1].s;
	tint ret = 0;
	tint maxi = -INF;
	FOR(i, 1, n+1){
		maxi = max(maxi, a[i-1].f-s[i-1]);
		ret = max(ret, s[i]-a[i-1].f+maxi);
	}
	cout << ret << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 3 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 2 ms 620 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 620 KB Output is correct
38 Correct 2 ms 620 KB Output is correct
39 Correct 3 ms 620 KB Output is correct
40 Correct 2 ms 620 KB Output is correct
41 Correct 2 ms 620 KB Output is correct
42 Correct 3 ms 620 KB Output is correct
43 Correct 3 ms 620 KB Output is correct
44 Correct 4 ms 640 KB Output is correct
45 Correct 3 ms 620 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 2 ms 620 KB Output is correct
48 Correct 2 ms 620 KB Output is correct
49 Correct 2 ms 620 KB Output is correct
50 Correct 3 ms 620 KB Output is correct
51 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 3 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 2 ms 620 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 620 KB Output is correct
38 Correct 2 ms 620 KB Output is correct
39 Correct 3 ms 620 KB Output is correct
40 Correct 2 ms 620 KB Output is correct
41 Correct 2 ms 620 KB Output is correct
42 Correct 3 ms 620 KB Output is correct
43 Correct 3 ms 620 KB Output is correct
44 Correct 4 ms 640 KB Output is correct
45 Correct 3 ms 620 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 2 ms 620 KB Output is correct
48 Correct 2 ms 620 KB Output is correct
49 Correct 2 ms 620 KB Output is correct
50 Correct 3 ms 620 KB Output is correct
51 Correct 2 ms 620 KB Output is correct
52 Correct 213 ms 24812 KB Output is correct
53 Correct 217 ms 24720 KB Output is correct
54 Correct 203 ms 24704 KB Output is correct
55 Correct 203 ms 24692 KB Output is correct
56 Correct 206 ms 24684 KB Output is correct
57 Correct 205 ms 24684 KB Output is correct
58 Correct 206 ms 24812 KB Output is correct
59 Correct 203 ms 24812 KB Output is correct
60 Correct 201 ms 24684 KB Output is correct
61 Correct 202 ms 24812 KB Output is correct
62 Correct 200 ms 24684 KB Output is correct
63 Correct 200 ms 24684 KB Output is correct
64 Correct 206 ms 24812 KB Output is correct
65 Correct 205 ms 24684 KB Output is correct
66 Correct 202 ms 24684 KB Output is correct
67 Correct 207 ms 24684 KB Output is correct
68 Correct 202 ms 24684 KB Output is correct