• + 4 comments

    My solution in C:

    #include <math.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <limits.h>
    #include <stdbool.h>
    
    int main(){
        int *h = malloc(sizeof(int) * 26);
        for(int h_i = 0; h_i < 26; h_i++){
           scanf("%d",&h[h_i]);
        }
        char* word = (char *)malloc(512000 * sizeof(char));
        scanf("%s",word);
        int max = 0;
        size_t len = strlen(word);
        for(size_t i = 0; i < len; i++) {
            int ind = word[i] - 'a';
            if(h[ind] > max) {
                max = h[ind];
            }
        }
        
        printf("%d\n", max * len);
        return 0;
    }