이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int N = 5e5 + 5;
typedef struct struc{
ll a, b;
}art;
art arr[N];
int n;
bool cmp(art x, art y)
{
return x.a<y.a;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("sample-02-in.txt","r",stdin);
cin>>n;
for(int i = 1;i<=n;i++)
{
cin>>arr[i].a>>arr[i].b;
}
sort(arr+1, arr+n+1, cmp);
ll maks = 0;
ll ans = 0;
int poz = 1;
ll pret = arr[1].a;
for(int i = 2;i<=n;i++)
{
if(arr[i].a==pret)
{
arr[poz].b += arr[i].b;
}
else
{
pret = arr[i].a;
poz++;
arr[poz].a = arr[i].a;
arr[poz].b = arr[i].b;
}
}
/* for(int i = 1;i<=poz;i++)
cout<<arr[i].a<<" "<<arr[i].b<<endl; */
for(int i = 1;i<=poz;i++)
{
if(i==1)
{
ans = arr[1].b;
maks = arr[1].b + arr[1].a;
}
else
{
ans = max(ans, maks - arr[i].a + arr[i].b);
maks = max(maks, maks + arr[i].b);
maks = max(maks, arr[i].b + arr[i].a);
}
}
cout<<ans;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |