結果

問題 No.115 遠足のおやつ
ユーザー tetsuzuki1115
提出日時 2018-01-27 16:54:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 954 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 81,484 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 13:51:19
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 29 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

bool is_ok( int a, int d, int k, int n ) {
    
    if ( n-a < k ) { return false; }
    
    return ( ( a*k + k*(k+1)/2 ) <= d && d <= ( n*k-(k-1)*k/2 ) );    
}

int main() {
    
    int N,D,K;
    cin >> N >> D >> K;
    
    if ( N < K ) { cout << -1 << endl; return 0; }
    
    vector<int> A;
    for ( int i = 1; i <= N; i++ ) {
        if ( is_ok( i, D-i, K-1, N ) ) {
            A.push_back(i);
            K--;
            D -= i;
        }
    }
    
    if ( K ) { cout << -1 << endl; }
    
    for ( int i = 0; i < A.size(); i++ ) {
        cout << A[i];
        if ( i != A.size()-1 ) { cout << " "; }
    }
    cout << endl;
    
    return 0;
}
0