QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113713#3123. Stovepdstiago0 1ms3556kbC++141.4kb2023-06-19 05:39:472023-06-19 05:39:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 05:39:49]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3556kb
  • [2023-06-19 05:39:47]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
 
#define MOD 1000000007
#define mxn (int) 1e5+5
#define mxm (int) 1e5+5
#define f first
#define s second
#define pb push_back
#define es " "
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define fastio ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> pip;
typedef unsigned long long ull;

int n, k;
ll v[mxn];

ll solve(ll x){
    ll atual=v[1];
    int cont=1;

    for(int i=1; i<=n; i++){
        if((v[i]+1)-atual>x){
            cont++;
            atual=v[i];
        }
    }
    if(cont<=k) return 1;
    return 0;
}

ll ans(ll x){
    ll atual=v[1], resp=0;
    int cont=1;

    for(int i=1; i<=n; i++){
        if((v[i]+1)-atual>x){
            resp+=(v[i-1]+1)-atual;
            cont++;
            atual=v[i];
        }
    }
    resp+=(v[n]+1)-atual;
    return resp;
}

int main(){
    fastio;
    cin >> n >> k;

    for(int i=1; i<=n; i++){
        cin >> v[i];
    }

    ll ini=1, fim=1e9, meio, resp;

    while(ini<=fim){
        meio=(ini+fim)>>1;

        if(solve(meio)){
            fim=meio-1;
            resp=meio;
        }else{
            ini=meio+1;
        }
    }
    cout << ans(resp);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 3460kb

input:

10 1
1
3
4
6
8
10
13
14
15
20

output:

20

result:

ok single line: '20'

Test #2:

score: -20
Wrong Answer
time: 1ms
memory: 3556kb

input:

10 3
2
3
6
9
10
11
13
14
17
18

output:

15

result:

wrong answer 1st lines differ - expected: '13', found: '15'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%