Submission #27072

# Submission time Handle Problem Language Result Execution time Memory
27072 2017-07-09T07:03:40 Z 아인타(#1126) Wine Tasting (FXCUP2_wine) C++
0 / 1
0 ms 2292 KB
/*#include<cstdio>
#include<algorithm>
using namespace std;
int w[12], v[11], head, tail, CC, pp;
int chk[1030][1030][2][2];
struct point{
    int a, b, ck, r1, r2, ck2;
}Q[2010000], TQ[2010000];
void Ins(int m1, int m2, int t1, int t2, int ck, int r1, int r2, int ck2){
    if(ck2 && t2)return;
    if(m1&(1<<t1))return;
    if(!ck2 && (m2&(1<<t2)))return;
    if(pp == 1000000000 && ck == 1)return;
    m1 |= (1<<t1);
    m2 |= (1<<t2);
    if(ck2 == 0 && t2 == 0){
        ck2 = 1;
        if(!chk[m1][m2][ck][ck2]){
            r1 += pp * t1;
            r2 += pp * t2;
            TQ[++CC] = {m1,m2,ck,r1,r2,ck2};
            chk[m1][m2][ck][ck2] = 1;
            r1 -= pp * t1;
            r2 -= pp * t2;
        }
        ck2 = 0;
    }
    if(chk[m1][m2][ck][ck2])return;
    r1 += pp * t1;
    r2 += pp * t2;
    chk[m1][m2][ck][ck2] = 1;
    TQ[++CC] = {m1,m2,ck,r1,r2,ck2};
}
bool Repeat(int a){
    int t = a;
    int v[10] = {0};
    while(t>10){
        if(v[t%10])return true;
        v[t%10] = true;
        t/=10;
    }
    return false;
}
bool Pos(int n, int ccc){
    if(ccc){
        while(1){}
    }
    int m = 0, tn = n;
    while(n){
        w[++m] = n%10;
        n/=10;
    }
    n = tn;
    head = tail = 0;
    Q[++tail] = {0,0,0,0,0,0};
    pp = 1;
    int i, j, k;
    for(i=1;i<=m;i++){
        CC = 0;
        for(j=1;j<=tail;j++){
            if(i==m && w[i] == 1 && Q[j].ck == 1){
                if(!ccc)printf( "2 %d %d\n",Q[i].r1, Q[i].r2);
                else printf("3 %d %d %d\n",ccc,Q[i].r1,Q[i].r2);
                return true;
            }
            int a = w[i] - Q[j].ck, m1 = Q[j].a, m2 = Q[j].b;
            for(k=0;k<10;k++){
                if(a >= k){
                    Ins(m1, m2, k, a-k, 0, Q[j].r1, Q[j].r2, Q[j].ck2);
                }
                if(a < k){
                    Ins(m1, m2, k, 10+a-k, 1, Q[j].r1, Q[j].r2, Q[j].ck2);
                }
            }
        }
        pp*=10;
        for(j=1;j<=CC;j++){
            chk[TQ[j].a][TQ[j].b][TQ[j].ck][TQ[j].ck2] = 0;
            Q[j] = TQ[j];
        }
        tail = CC;
    }
    for(i=1;i<=tail;i++){
        if(Q[i].ck == 0){
            if(Q[i].r1 + Q[i].r2 != n){
                while(1){}
            }
            if(Repeat(Q[i].r1) || Repeat(Q[i].r2)){
                fprintf(stderr,"%d %d %d\n",Q[i].r1, Q[i].r2, n);
                while(1){}
            }
            if(!ccc)printf( "2 %d %d\n",Q[i].r1, Q[i].r2);
            else printf("3 %d %d %d\n",ccc,Q[i].r1,Q[i].r2);
            return true;
        }
    }
    return false;
}
int main(){
    int i, j, k;
    int TC, n;
    freopen("/Users/joseunghyeon/Downloads/d2.in","r", stdin);
    freopen("/Users/joseunghyeon/Desktop/code/160929/0409/0409/output.txt","w",stdout);
    scanf("%d",&TC);
    while(TC--){
        fprintf(stderr, "%d\n",TC);
        scanf("%d",&n);
        int tn = n;
        for(i=0;i<10;i++)v[i]=0;
        int ck = 0, m = 0;
        head = 0, tail = 0;
        while(n){
            if(v[n%10])ck = 1;
            v[n%10] = 1;
            w[++m] = n%10;
            n/=10;
        }
        n = tn;
        if(!ck){
            printf("%d %d\n",1, n);
            continue;
        }
        for(i=0;;i+=19){
            if(i && Repeat(i))continue;
            if(Pos(n-i, i))break;
        }
    }
}*/
#include<cstdio>
#include<algorithm>
using namespace std;
int n, K, w[301000];
long long res;
int main(){
    int i;
    scanf("%d%d",&n,&K);
    for(i=1;i<=n;i++)scanf("%d",&w[i]);
    sort(w+1,w+n+1);
    for(i=n;i>n-(K+1)/2;i--)res += w[i];
    for(i=1;i<=K/2;i++)res -= w[i];
    printf("%lld\n",res);
}

Compilation message

wine.cpp: In function 'int main()':
wine.cpp:136:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&K);
                        ^
wine.cpp:137:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%d",&w[i]);
                                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2292 KB Output is correct
2 Incorrect 0 ms 2292 KB Output isn't correct
3 Halted 0 ms 0 KB -