답안 #160602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160602 2019-10-28T17:07:22 Z shashwatchandra Art Exhibition (JOI18_art) C++17
100 / 100
331 ms 36732 KB
/*input
15
1543361732 260774320
2089759661 257198921
1555665663 389548466
4133306295 296394520
2596448427 301103944
1701413087 274491541
2347488426 912791996
2133012079 444074242
2659886224 656957044
1345396764 259870638
2671164286 233246973
2791812672 585862344
2996614635 91065315
971304780 488995617
1523452673 988137562
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 5e5+1;
vector<int> indices;
int a[N];
int b[N];
int v[N];
int g[N];
int pref[N];
int n;

bool cmp(int a1,int b1){
	return a[a1] < a[b1]; 
}

void solve(){
  	cin >> n;
  	RE(i,n){
  		cin >> a[i] >> v[i];
  		indices.pb(i);
  	}
  	sort(all(indices),cmp);
  	RE(i,n){
  		b[i] = a[indices[i-1]];
  		g[i] = v[indices[i-1]];
  	//	cout << b[i] << " " << g[i] << endl;
  	}

  	pref[0] = 0;
  	RE(i,n){
  		pref[i] = pref[i-1]+g[i];
  	}
  	int ans = g[1];
  	int mn = b[1];
  	for(int i = 2;i <= n;i++){
  		mn = max(mn,b[i]-pref[i-1]);
  		ans = max(ans,mn+pref[i]-b[i]);
  	}
  	cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 5 ms 888 KB Output is correct
30 Correct 5 ms 764 KB Output is correct
31 Correct 5 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 5 ms 764 KB Output is correct
35 Correct 6 ms 888 KB Output is correct
36 Correct 5 ms 760 KB Output is correct
37 Correct 5 ms 760 KB Output is correct
38 Correct 5 ms 760 KB Output is correct
39 Correct 5 ms 760 KB Output is correct
40 Correct 5 ms 732 KB Output is correct
41 Correct 5 ms 760 KB Output is correct
42 Correct 5 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 7 ms 764 KB Output is correct
45 Correct 5 ms 760 KB Output is correct
46 Correct 5 ms 760 KB Output is correct
47 Correct 5 ms 760 KB Output is correct
48 Correct 5 ms 760 KB Output is correct
49 Correct 5 ms 760 KB Output is correct
50 Correct 5 ms 888 KB Output is correct
51 Correct 5 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 5 ms 760 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 5 ms 888 KB Output is correct
30 Correct 5 ms 764 KB Output is correct
31 Correct 5 ms 760 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 5 ms 764 KB Output is correct
35 Correct 6 ms 888 KB Output is correct
36 Correct 5 ms 760 KB Output is correct
37 Correct 5 ms 760 KB Output is correct
38 Correct 5 ms 760 KB Output is correct
39 Correct 5 ms 760 KB Output is correct
40 Correct 5 ms 732 KB Output is correct
41 Correct 5 ms 760 KB Output is correct
42 Correct 5 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 7 ms 764 KB Output is correct
45 Correct 5 ms 760 KB Output is correct
46 Correct 5 ms 760 KB Output is correct
47 Correct 5 ms 760 KB Output is correct
48 Correct 5 ms 760 KB Output is correct
49 Correct 5 ms 760 KB Output is correct
50 Correct 5 ms 888 KB Output is correct
51 Correct 5 ms 760 KB Output is correct
52 Correct 325 ms 36556 KB Output is correct
53 Correct 320 ms 36652 KB Output is correct
54 Correct 314 ms 36580 KB Output is correct
55 Correct 328 ms 36732 KB Output is correct
56 Correct 311 ms 36576 KB Output is correct
57 Correct 317 ms 36568 KB Output is correct
58 Correct 323 ms 36708 KB Output is correct
59 Correct 325 ms 36676 KB Output is correct
60 Correct 329 ms 36704 KB Output is correct
61 Correct 319 ms 36584 KB Output is correct
62 Correct 313 ms 36568 KB Output is correct
63 Correct 315 ms 36688 KB Output is correct
64 Correct 315 ms 36576 KB Output is correct
65 Correct 331 ms 36576 KB Output is correct
66 Correct 319 ms 36676 KB Output is correct
67 Correct 314 ms 36648 KB Output is correct
68 Correct 316 ms 36604 KB Output is correct