#include <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
if(a>b) swap(a,b);
if(a==0) return a+b;
return gcd(b%a,a);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool is_prime(ll n){
ll k=sqrt(n);
if(n==2) return true;
if(n<2||n%2==0||k*k==n) return false;
for(int i=3;i<=k;i+=2){
if(n%i==0){
return false;
}
}
return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
ll t=1,n,a,b;
vector<pll>vt;
ll funk(int ind,int ans){
return ans-vt[ind].S;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a>>b;
vt.pb({a,b});
}
sort(all(vt));
ll ans=0,k=0;
int l=0;
for(int i=0;i<n;i++){
k+=vt[i].S;
ans=max(ans,k);
if(i==n-1) break;
k-=(vt[i+1].F-vt[i].F);
if(k<0){
k=0;
}
}
cout<<ans<<endl;
}
signed main(){
IOS;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message
art.cpp: In function 'void solve()':
art.cpp:57:9: warning: unused variable 'l' [-Wunused-variable]
57 | int l=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
388 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
388 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
548 KB |
Output is correct |
28 |
Correct |
2 ms |
568 KB |
Output is correct |
29 |
Correct |
2 ms |
572 KB |
Output is correct |
30 |
Correct |
2 ms |
584 KB |
Output is correct |
31 |
Correct |
2 ms |
616 KB |
Output is correct |
32 |
Correct |
2 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
592 KB |
Output is correct |
34 |
Correct |
2 ms |
640 KB |
Output is correct |
35 |
Correct |
2 ms |
568 KB |
Output is correct |
36 |
Correct |
2 ms |
580 KB |
Output is correct |
37 |
Correct |
2 ms |
552 KB |
Output is correct |
38 |
Correct |
2 ms |
588 KB |
Output is correct |
39 |
Correct |
2 ms |
580 KB |
Output is correct |
40 |
Correct |
2 ms |
588 KB |
Output is correct |
41 |
Correct |
2 ms |
588 KB |
Output is correct |
42 |
Correct |
2 ms |
576 KB |
Output is correct |
43 |
Correct |
2 ms |
588 KB |
Output is correct |
44 |
Correct |
2 ms |
588 KB |
Output is correct |
45 |
Correct |
2 ms |
588 KB |
Output is correct |
46 |
Correct |
2 ms |
580 KB |
Output is correct |
47 |
Correct |
3 ms |
588 KB |
Output is correct |
48 |
Correct |
2 ms |
584 KB |
Output is correct |
49 |
Correct |
2 ms |
588 KB |
Output is correct |
50 |
Correct |
2 ms |
572 KB |
Output is correct |
51 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
388 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
548 KB |
Output is correct |
28 |
Correct |
2 ms |
568 KB |
Output is correct |
29 |
Correct |
2 ms |
572 KB |
Output is correct |
30 |
Correct |
2 ms |
584 KB |
Output is correct |
31 |
Correct |
2 ms |
616 KB |
Output is correct |
32 |
Correct |
2 ms |
588 KB |
Output is correct |
33 |
Correct |
2 ms |
592 KB |
Output is correct |
34 |
Correct |
2 ms |
640 KB |
Output is correct |
35 |
Correct |
2 ms |
568 KB |
Output is correct |
36 |
Correct |
2 ms |
580 KB |
Output is correct |
37 |
Correct |
2 ms |
552 KB |
Output is correct |
38 |
Correct |
2 ms |
588 KB |
Output is correct |
39 |
Correct |
2 ms |
580 KB |
Output is correct |
40 |
Correct |
2 ms |
588 KB |
Output is correct |
41 |
Correct |
2 ms |
588 KB |
Output is correct |
42 |
Correct |
2 ms |
576 KB |
Output is correct |
43 |
Correct |
2 ms |
588 KB |
Output is correct |
44 |
Correct |
2 ms |
588 KB |
Output is correct |
45 |
Correct |
2 ms |
588 KB |
Output is correct |
46 |
Correct |
2 ms |
580 KB |
Output is correct |
47 |
Correct |
3 ms |
588 KB |
Output is correct |
48 |
Correct |
2 ms |
584 KB |
Output is correct |
49 |
Correct |
2 ms |
588 KB |
Output is correct |
50 |
Correct |
2 ms |
572 KB |
Output is correct |
51 |
Correct |
2 ms |
588 KB |
Output is correct |
52 |
Correct |
169 ms |
20760 KB |
Output is correct |
53 |
Correct |
177 ms |
20184 KB |
Output is correct |
54 |
Correct |
168 ms |
20848 KB |
Output is correct |
55 |
Correct |
174 ms |
20844 KB |
Output is correct |
56 |
Correct |
165 ms |
20800 KB |
Output is correct |
57 |
Correct |
168 ms |
20868 KB |
Output is correct |
58 |
Correct |
176 ms |
20844 KB |
Output is correct |
59 |
Correct |
172 ms |
19808 KB |
Output is correct |
60 |
Correct |
178 ms |
19916 KB |
Output is correct |
61 |
Correct |
174 ms |
18924 KB |
Output is correct |
62 |
Correct |
178 ms |
18760 KB |
Output is correct |
63 |
Correct |
181 ms |
19716 KB |
Output is correct |
64 |
Correct |
179 ms |
18760 KB |
Output is correct |
65 |
Correct |
169 ms |
20836 KB |
Output is correct |
66 |
Correct |
170 ms |
20808 KB |
Output is correct |
67 |
Correct |
167 ms |
20836 KB |
Output is correct |
68 |
Correct |
198 ms |
20888 KB |
Output is correct |