답안 #123120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123120 2019-06-30T09:00:40 Z Hideo Art Exhibition (JOI18_art) C++14
0 / 100
2 ms 256 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < ll, ll >
#define pii pair < int, pi >
#define vii vector < pi >

const int N = 3e5 + 7;
const int INF = 1e9 + 7;

pi a[N];
ll pr[N];
ll rs1, rs2, mx;
int n;
int l1, r1, l2, r2;

main(){
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%lld%lld", &a[i].fr, &a[i].sc);
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
        pr[i] = pr[i - 1] + a[i].sc;

    for (int i = 1; i <= n; i++){
        if (mx < pr[i] - a[i].fr){
            mx = pr[i] - a[i].fr;
            r1 = i;
        }
    }
    mx = 0;
    for (int i = 1; i <= r1; i++){
        if (mx < a[i].fr - pr[i - 1]){
            mx = a[i].fr - pr[i - 1];
            l1 = i;
        }
    }
    mx = 0;
    for (int i = 1; i <= n; i++){
        if (mx < a[i].fr - pr[i - 1]){
            mx = a[i].fr - pr[i - 1];
            l2 = i;
        }
    }
    mx = 0;
    for (int i = l2; i <= n; i++){
        if (mx < 1LL * pr[i] - a[i].fr){
            mx = pr[i] - a[i].fr;
            r2 = i;
        }
    }
    rs1 = pr[r1] + a[l1].fr - pr[l1 - 1] - a[r1].fr;
    rs2 = pr[r2] + a[l2].fr - pr[l2 - 1] - a[r2].fr;
    cout << max(rs1, rs2);
}

Compilation message

art.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
art.cpp: In function 'int main()':
art.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a[i].fr, &a[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -