Submission #1179541


Source Code Expand

/*************************************************************************
    > File Name: B.cpp
    > Author: Akira
    > Mail: qaq.febr2.qaq@gmail.com
    > Created Time: 2017年03月18日 星期六 20时30分11秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<vector>
#include<set>
#include<list>
#include<ctime>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))

using namespace std;

#define MaxN 5005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1e9+7;
const int eps = 1e-8;
#define bug cout << 88888888 << endl;
int N;
LL K;
LL node[MaxN];
int main()
{
    while(~scanf("%d%lld", &N, &K))
    {
        LL sum = 0;
        for(int i=1;i<=N;i++)
        {
            scanf("%lld", node+i);
        }
        sort(node+1, node+1+N);
        for(int i=1;i<=N;i++)
        {
            if(sum<K)
            {
                sum += node[i];
            }
            else break;
        }
        if(sum<K) 
        {
            printf("%d\n", N);
            continue;
        }
        LL* it = (upper_bound(node+1,node+1+N, K));
        it -=1;
        int ans = 0;

        for(int i=1;i<=N;i++)
        {
            if(sum>=K)
            {
                sum -= node[i];
            }
            
            if(sum<K)
            {
                ans = i-1;
                break;
            }
        }
        LL* low = it;
        LL* high = it;
        int lim = ans;
        while( low!= node+lim )
        {
            int cnt = 0;
            for(LL* i = low;i<=high;i++)
            {
                cnt += *i;
            }
            while(cnt>=K)
            {
                cnt -= *high;
                high--;
            }
            //cout << cnt << endl;
            int i = ans;
            while(i>0)
            {
                int tmp = cnt+node[i];
                if(tmp>=K) ans--,i--;
                else
                {
                    int j = i-1;
                    for(j;j>0;j--)
                    {
                        tmp += node[j];
                        if(tmp>=K)
                        {
                            ans -= (i-j+1);
                            break;
                        }
                    }
                    i = j;
                }
            }
            if(ans==0) break;
            low--;
        }
        printf("%d\n", ans);

    }
}

Submission Info

Submission Time
Task D - No Need
User over
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2852 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:48:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", node+i);
                                  ^

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 300 / 300 300 / 300
Status
AC × 3
AC × 26
AC × 51
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
Subtask 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 1 ms 256 KB
1_009.txt AC 1 ms 256 KB
1_010.txt AC 1 ms 256 KB
1_011.txt AC 1 ms 256 KB
1_012.txt AC 1 ms 256 KB
1_013.txt AC 1 ms 256 KB
1_014.txt AC 1 ms 256 KB
1_015.txt AC 1 ms 256 KB
1_016.txt AC 1 ms 256 KB
1_017.txt AC 1 ms 256 KB
1_018.txt AC 1 ms 256 KB
1_019.txt AC 1 ms 256 KB
1_020.txt AC 1 ms 256 KB
1_021.txt AC 1 ms 256 KB
1_022.txt AC 1 ms 256 KB
1_023.txt AC 1 ms 256 KB
1_024.txt AC 1 ms 256 KB
1_025.txt AC 1 ms 256 KB
2_026.txt AC 1 ms 256 KB
2_027.txt AC 1 ms 256 KB
2_028.txt AC 1 ms 256 KB
2_029.txt AC 1 ms 256 KB
2_030.txt AC 2 ms 256 KB
2_031.txt AC 2 ms 256 KB
2_032.txt AC 2 ms 256 KB
2_033.txt AC 2 ms 256 KB
2_034.txt AC 2 ms 256 KB
2_035.txt AC 2 ms 256 KB
2_036.txt AC 2 ms 256 KB
2_037.txt AC 1 ms 256 KB
2_038.txt AC 1 ms 256 KB
2_039.txt AC 1 ms 256 KB
2_040.txt AC 2 ms 256 KB
2_041.txt AC 2 ms 256 KB
2_042.txt AC 2 ms 256 KB
2_043.txt AC 2 ms 256 KB
2_044.txt AC 2 ms 256 KB
2_045.txt AC 2 ms 256 KB
2_046.txt AC 2 ms 256 KB
2_047.txt AC 2 ms 256 KB
2_048.txt AC 2 ms 256 KB
2_049.txt AC 2 ms 256 KB
2_050.txt AC 2 ms 256 KB