답안 #866051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866051 2023-10-25T10:47:36 Z farica Homecoming (BOI18_homecoming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N=2000000;
const int N=1000001;

long long sum_a[MAX_N], sum_b[MAX_N];
int n;

int distance(int l, int r) {
    if(l<=r) return (r-l+1);
    else return n-r+l+1;
}

int decrease(int i, int x) {
    if(i>=x) return i-x;
    return n-(x-i);
}

int prefix_suma(int l, int r) {
    if(l<=r) {
        int ret = sum_a[r];
        if(l) ret -= sum_a[l-1];
        return ret;
    }
    int ret=0;
    if(l) ret += sum_a[n-1] - sum_a[l-1];
    else ret += sum_a[n-1];
    ret += sum_a[r];
    return ret;
}

int prefix_sumb(int l, int r) {
    if(l<=r) {
        int ret = sum_b[r];
        if(l) ret -= sum_b[l-1];
        return ret;
    }
    int ret=0;
    if(l) ret += sum_b[n-1] - sum_b[l-1];
    else ret += sum_b[n-1];
    ret += sum_b[r];
    return ret;
}

void solve() {
    int k;
    cin >> n >> k;
    int a[n], b[n];
    for(int i=0; i<n; ++i) {
        cin >> a[i];
        sum_a[i]=a[i];
        if(i) sum_a[i]+=sum_a[i-1];
    }
    for(int i=0; i<n; ++i) {
        cin >> b[i];
        sum_b[i]=b[i];
        if(i) sum_b[i]+=sum_b[i-1];
    }
    long long ans=0;
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            long long cnt = 0;
            if(distance(i, j)>=k) cnt += prefix_suma(i, decrease(j, k-1));
            cnt -= prefix_sumb(i, j);
            ans=max(ans, cnt);
        }
    }
    cout << ans << endl;
}

int main()
{
    int T=1;
    while(T--) solve();

    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccq2qmgG.o: in function `main':
homecoming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccoUmhZC.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccoUmhZC.o: in function `main':
grader.cpp:(.text.startup+0xdf): undefined reference to `solve(int, int, int*, int*)'
collect2: error: ld returned 1 exit status