C1. Encryption (easy)

C1. Encryption (easy)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one looks.

Heidi is presented with a screen that shows her a sequence of integers A and a positive integer p. She knows that the encryption code is a single number S, which is defined as follows:

Define the score of X to be the sum of the elements of X modulo p.

Heidi is given a sequence A that consists of N integers, and also given an integer p. She needs to split A into 2 parts such that:

  • Each part contains at least 1 element of A, and each part consists of contiguous elements of A.
  • The two parts do not overlap.
  • The total sum S of the scores of those two parts is maximized. This is the encryption code.

Output the sum S, which is the encryption code.

Input

The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 0002 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.

The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000].

Output

Output the number S as described in the problem statement.

Examples
input
Copy
4 10
3 4 7 2
output
Copy
16
input
Copy
10 12
16 3 24 13 9 8 7 5 12 12
output
Copy
13
Note

In the first example, the score is maximized if the input sequence is split into two parts as (3, 4)(7, 2). It gives the total score of .

In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then, the score is .

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long a[100002];
    long long n,p,i,ma=-1,m=0,x,y,xx,yy;
    cin>>n>>p;
    for(i=1;i<=n;i++){
        cin>>a[i];
        m+=a[i];
    }
    x = 0;
    y = m;
    for(i=2;i<=n;i++){
        x += a[i-1];
        y -= a[i-1];
        xx = x%p;
        yy = y%p;
        ma = max(ma,xx+yy);
    }
    cout<<ma<<endl;
    return 0;
}
### Crystal Decisions 加密模块概述 `com.crystaldecisions.celib.encryption` 是 SAP Crystal Reports 中用于处理数据加密解密操作的核心组件之一。该库提供了多种安全机制来保护敏感信息,防止未经授权的数据访问。 #### 加密实现方式 Crystal Reports 使用对称加密算法 AES (Advanced Encryption Standard),默认情况下采用 CBC 模式[^1]: ```java import com.crystaldecisions.celib.encryption.*; public class EncryptionExample { public static void main(String[] args) throws Exception { String originalData = "Sensitive Information"; // 初始化加密器实例 IEncryption encryptionService = new Encryption(); // 设置密钥和初始化向量(IV) byte[] keyBytes = "your-secret-key".getBytes("UTF-8"); byte[] ivBytes = "initialization-vector".getBytes("UTF-8"); // 执行加密过程 byte[] encryptedData = encryptionService.encrypt(originalData.getBytes(), keyBytes, ivBytes); System.out.println("Encrypted Data: " + Base64.getEncoder().encodeToString(encryptedData)); // 解密过程 byte[] decryptedData = encryptionService.decrypt(encryptedData, keyBytes, ivBytes); System.out.println("Decrypted Data: " + new String(decryptedData, "UTF-8")); } } ``` 需要注意的是,在实际应用环境中应当妥善保管密钥材料并遵循最佳实践指南以确保安全性[^2]。 #### 常见问题及解决方案 当涉及到 `com.crystaldecisions.celib.encryption` 的时候,可能会遇到如下几个典型问题: - **版本兼容性** 如果不同开发人员使用的 SDK 版本不一致,则可能导致加密/解密失败。建议团队成员统一使用相同版本的 Crystal Reports 库文件,特别是像 `CrystalDecisions.ReportSource.dll` 和其他核心依赖项这样的关键组件。 - **配置错误** 配置不当也可能引发异常情况。例如,如果应用程序试图加载不存在或路径设置有误的安全提供者类,将会抛出 NoSuchProviderException 异常。因此要仔细检查 Java 安全策略文件以及相关环境变量配置是否正确无误[^3]。 - **性能瓶颈** 对于大规模数据集而言,频繁调用加解密函数可能成为系统性能瓶颈所在。此时可以考虑批量处理或者异步执行等方式优化效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值